//LICA...MCA SEM-2
//Simply singly linklist..
//Same as maulin but maulin has done it wit doubly
#include
#include
#include
struct node
{
int data;
struct node *next;
};
void addbeg(struct node **start)
{
struct node *temp,*t;
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter Data Value\n");
scanf("%d",&temp->data);
if(*start==NULL)
{
temp->next=NULL;
*start=temp;
}
else
{ t=(struct node *)malloc(sizeof(struct node));
t=*start;
temp->next=*start;
*start=temp;
}
}
void addend(struct node **start)
{
struct node *temp,*list;
list=(struct node *)malloc(sizeof(struct node));
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data: ");
scanf("%d",&temp->data);
temp->next=NULL;
list=*start;
if(*start==NULL)
{
*start=temp;
}
else
{
while(list->next!=NULL)
{
list=list->next;
}
list->next=temp;
list=temp;
}
}
void addinbet(struct node **start)
{
int n,count=0;
struct node *temp,*list;
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter Value: ");
scanf("%d",&temp->data);
printf("Enter Node Position You Want to Add After :");
scanf("%d",&n);
list=*start;
while(list->next!=NULL)
{
count++;
if(count==n)
{
temp->next=list->next;
list->next=temp;
printf("Element Added Succesfully\n");
}
/* else
{
printf("Linklist is not yet reached this limit");
}*/
list=list->next;
}
}
void delstart(struct node **start)
{
// **start=start->next;
}
void delend(struct node **start)
{
struct node *list;
list=*start;
while(list->next->next!=NULL)
{
list=list->next;
}
list->next=NULL;
}
void delinbet(struct node **start)
{
int cout=0;
int n;
struct node *list;
list=*start;
printf("Enter postion you want to delete\n");
scanf("%d",&n);
while(list->next!=NULL)
{
cout++;
if(cout==n-1)
{
list->next=list->next->next;
printf("Node Deleted Succesfully\n");
}
list=list->next;
}
}
void linksort(struct node **start)
{
int temp ;
struct node *t1,*t2=(struct node *)malloc(sizeof(struct node));
for(t1=*start;t1;t1=t1->next)
{
for(t2=t1;t2;t2=t2->next)
{
if(t1->data>t2->data)
{
temp=t1->data;
t1->data=t2->data;
t2->data=temp;
}
}
}
}
void display(struct node **start)
{
struct node * disp;
disp=(struct node *)malloc(sizeof(struct node));
disp=*start;
while(disp)
{
printf("%d\t",disp->data);
disp=disp->next;
}
}
void main()
{
int ch;
struct node *start=NULL;
char conn;
clrscr();
do
{
printf("\n1.Create @ Begning");
printf("\n2.Create @ End");
printf("\n4.Inbetween");
printf("\n5.Delete Start");
printf("\n6.Delete End");
printf("\n7.Delete Inbetween");
printf("\n8.LinkList Sort");
printf("\n3.Display");
printf("\n0.Exit\n");
scanf("\n%d",&ch);
switch(ch)
{
case 1:
addbeg(&start);
break;
case 2:
addend(&start);
break;
case 3:
display(&start);
break;
case 4:
addinbet(&start);
break;
case 5:
delstart(&start);
break;
case 6:
delend(&start);
break;
case 7:
delinbet(&start);
break;
case 8:
linksort(&start);
break;
case 0:
break;
};
printf("\nWant to continue\n");
fflush(0);
scanf("%c",&conn);
}while(conn=='y'||conn=='Y');
getch();
}
----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com
hey friends..
ReplyDeleteits simply an example which will help u in polynomial operations as their we need to pass our linklist head to our UDF functions..
i m working on dat.. so ASAP! il complete my polynomial prog ill post it...