head 1.1;
access;
symbols;
locks
Emblogic:1.1; strict;
comment @ * @;
1.1
date 2014.03.25.09.08.55; author Emblogic; state Exp;
branches;
next ;
desc
@this is a program of linked list
to insert the node at beginning,position and end
to delete the node at begining,position,end
to dispay the linked list
@
1.1
log
@Initial revision
@
text
@#include
#include
struct node
{
int data;
struct node *next;
};
struct node * create_node();
struct node * insert_node(struct node *);
struct node * delete_node(struct node *);
void display(struct node *);
struct node * insert_beg(struct node *);
struct node * insert_pos(struct node *);
struct node * insert_end(struct node *);
struct node * delete_beg(struct node *);
struct node * delete_pos(struct node *);
struct node * delete_end(struct node *);
int main()
{
struct node *start;
int ch;
do
{
printf(“1: create_node\n”);
printf(“2: insert_node\n”);
printf(“3: delete_node\n”);
printf(“4: display\n”);
printf(“5: exit\n”);
printf(“enter your choice\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
start=create_node();
break;
case 2:
start=insert_node(start);
break;
case 3:
start=delete_node(start);
break;
case 4:
display(start);
break;
case 5:
break;
}
}while(ch != 5);
}
struct node * create_node()
{
struct node *start;
start=malloc(sizeof(struct node));
printf(” enter data\n”);
scanf(“%d”,&start->data);
start->next= NULL;
return start;
}
struct node * insert_node(struct node *start)
{
int ch;
printf(“1: insert at begining\n”);
printf(“2: insert at position\n”);
printf(“3: insert at end\n”);
printf(“enter your choice\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
start=insert_beg(start);
break;
case 2:
start=insert_pos(start);
break;
case 3:
start=insert_end(start);
break;
}
return start;
}
struct node * delete_node(struct node *start)
{
int ch;
printf(“1: delete at begining\n”);
printf(“2: delete at position\n”);
printf(“3: delete at end\n”);
printf(“enter your choice\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
start=delete_beg(start);
break;
case 2:
start=delete_pos(start);
break;
case 3:
start=delete_end(start);
break;
}
return start;
}
void display(struct node *start)
{
struct node *temp;
temp=start;
while(temp != NULL)
{
printf(“the data is %d”,temp->data);
temp=temp->next;
}
}
struct node * insert_beg(struct node *start)
{
struct node *temp;
temp=start;
start=create_node();
start->next=temp;
return start;
}
struct node * insert_pos(struct node *start)
{
struct node *temp, *new;
int n,i;
temp=start;
printf(“enter the position\n”);
scanf(“%d”,&n);
for(i=0; i next;
}
new=create_node();
new->next=temp->next;
temp->next=new;
return start;
}
struct node * insert_end(struct node *start)
{
struct node *temp,*new;
temp=start;
while(temp != NULL)
{
temp=temp->next;
}
new=create_node();
temp->next=new;
new->next= NULL;
return start;
}
struct node * delete_beg(struct node *start)
{
struct node *temp;
temp= start;
start=start->next;
free(temp);
return start;
}
struct node * delete_pos(struct node *start)
{
struct node *temp, *prev;
int n,i;
temp=start;
printf(“enter the position\n”);
scanf(“%d”,&n);
for(i=0; i next;
}
prev->next=temp->next;
free(temp);
return start;
}
struct node * delete_end(struct node *start)
{
struct node *temp,*prev;
temp=start;
while(temp->next != NULL)
{
prev=temp;
temp=temp->next;
}
free(temp);
prev->next= NULL;
return start;
}
@