0% found this document useful (0 votes)
13 views4 pages

Drtrtuyu

The document contains code for a linked list program in C with functions to insert, delete and traverse nodes. It includes functions to insert and delete nodes from the beginning, end or at any position in the linked list as well as functions to display, reverse display and count the nodes.

Uploaded by

DebD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Drtrtuyu

The document contains code for a linked list program in C with functions to insert, delete and traverse nodes. It includes functions to insert and delete nodes from the beginning, end or at any position in the linked list as well as functions to display, reverse display and count the nodes.

Uploaded by

DebD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h> { case 8: traverse(H);


#include<stdlib.h> printf("\n1.Insert First \n2.Insert break;
Last \n3.Insert Before \n4.Insert After case 9: rev_display(H);
typedef struct llist \n5.Delete First \n6.Delete Last break;
{ \n7.Delete any \n8.Display"); case 10:count(H);
int info; printf("\n9.Reverse Display break;
struct llist*next; \n10.Count \n0.Exit"); case 0: exit(0);
}node; printf("\n Enter your choice: "); break;
node *insert_first(node *); scanf("%d",&c); default: printf("\n Wrong input.
node *insert_last(node *); switch(c) Please enter a choice between-
node *del_first(node *); { >1/2/3/4/5/6/7/8/9/10/0");
node *del_last(node *); case 1: H=insert_first(H); }
void traverse(node *); break; }
case 2: H= insert_last(H); return 0;
node *insert_after(node *); break; }
node *del_any(node *); case 3: H=insert_before(H);
node *insert_before(node *); break;
case 4: H = insert_after(H);
void rev_display(node *); break;
void count(node *); case 5: H= del_first(H);
int main() break;
{ case 6: H = del_last(H);
int c; break;
node *H= NULL; case 7: H = del_any(H);
while(1) break;
node *insert_first(node *H1) if(H1==NULL); while(p->next!=NULL);
{ { {
node *p = H1; H1=temp; p1=p;
H1 = (node *)malloc(sizeof(node)); return H1; p=p->next;
H1->next=p; } }
printf("\n Enter value: "); prev=H1; p1->next=NULL;
scanf("%d",&H1->info); while(prev->next!=NULL) free(p);
return(H1); { return(H1);
} prev=prev->next; }
node *insert_last(node *H1) } void traverse(node*H1)
{ prev->next=temp; {
node *temp,*prev; return H1; node*p=H1;
int n; } while(p!=NULL)
temp=(node *)malloc(sizeof(node)); node *del_first(node *H1) {
printf("\n Enter value : "); { printf("%d\t",p->info);
scanf("%d",&n); node*p= H1; p=p->next;
if(temp==NULL) H1=H1->next; }
{ free(p); }
printf("\n Memory allocation unsuccessful"); return (H1);
return H1; }
} node*del_last(node*H1)
temp->info=n; {
temp->next=NULL; node*p=H1;
node*p1=H1;
void rev_display(node*H1) p1=p->next; if(p==NULL)
{ p- {
if(H1==NULL) >next=(node*)malloc(sizeof(node)); printf("\n invalid input \n ");
{ p=p->next; return(H1);
return; p->next=p1; }
} printf("\n enter value \n"); else if(p==H1)
rev_display(H1->next); scanf("%d",&p->info); {
printf("%d\t",H1->info); return(H1);
} } H1=(node*)malloc(sizeof(node));
node*insert_after(node*H1) node*insert_before(node*H1) H1->next=p;
{ { printf("\n Enter value: ");
int v; int v; scanf("%d",H1->info);
node*p,*p1; node*p,*p1; return(H1);
p=p1=H1; p=p1=H1; }
printf("\n Enter value after which you printf("\n Enter value after which
want to insert: "); you want to insert: ");
scanf("%d",&v); scanf("%d",&v);
while(p!=NULL && p->info!=v) while(p!=NULL && p->info!=v)
{ {
p=p->next; p=p1;
} p1=p1->next;
if(p==NULL) }
{
printf("\n invalid input");
return(H1); }
else { void count(node*H)
{ printf("\n invalid input \n "); {
p1->next=(node*)malloc(sizeof(node)); return(H1); int c=0;
p=p->next; } node*p=H;
p->next=p1; else if(p==H1) while(p!=NULL)
printf("\n Enter value: "); { {
scanf("%d",&p->info); H1=H1->next; p=p->next;
return(H1); free(p); c++;
} return(H1); }
} } printf("%d",c);
node*del_any(node*H1) else }
{ {
int v; p1->next=p->next;
node*p,*p1; printf("%d is deleted",p-
p=p1=H1; >info);
printf("\n Enter value after which you want to free(p);
insert: "); return(H1);
scanf("%d",&v); }
while(p!=NULL && p->info!=v) }
{
p1=p;
p=p->next;
}
if(p==NULL)

You might also like