Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

Data Structure

Loading...

Published in: C / C++
1,499 Views

C Programmings of Data Structure with output.

Sayantan A / Kolkata

8 years of teaching experience

Qualification: M.Tech

Teaches: Chemistry, Computer Science, Mathematics, Physics, GATE Exam, JEXPO, MCA Entrance Exam (JECA), Polytechnic Entrance, Computer, IT

Contact this Tutor
  1. Q.NO-6 : MENU DRIVEN PROGRAM TO IMPLEMENT SINGLY CIRCULAR LINKED LIST #include struct node int data; struct node *next; *list-NULL; struct node struct node *temp; //function declarations void create(int); void display(); void insert beg(int); void insert end(int); void insert spec(int,int); void delete beg(); void delete end(); void delete spec(int); void main() int choice,num,pos,y=O,choice1; do{ printf("\n1.Create 1st node\n2.DispIay \n3.Insert\n4.DeIete \n"); printf("\nEnter your choice:\t scanf("%d",&choice); switch(choice) case 1: printf("\nEnter value to be stored in first node• scanf("%d",&num); create(num); break; case 2: printf("List is empty\n"); display(); break;
  2. position\n insert' case 3: printf("\nl .At beggining\n2.At end\n3.At specific printf("Enter your choice: scanf("%d",&choicel); switch(choicel) case 1: printf("\nEnter data: \t"); scanf("%d",&num); insert beg(num); break; case 2: printf("Enter data: \t"); scanf("%d",&num); insert end(num); break; case 3: printf("Enter the position after which to printf("\nEnter data to insert: \t"); scanf("%d",&num); insert spec(pos,num); break; break; case 4: printf("\nl .From beginning\n2.From end\n3.From specific postion\n"); printf("Enter your choice:\t scanf("%d",&choicel); switch(choicel) case 1: delete_beg(); break; case 2: delete end(); break; case 3: printf("Enter the position to "); delete spec(pos); break; break;
  3. printf("Do you want to repeat? (yes=l)\t scanf("%d",&y); l* Process to free the dynamically allocated list after program completes *l struct node *a, * b=NULL; b=a; b; free(b); free(a); list-NULL; printf("\n\nAIIocated memory freed.....\n\n"); void create(int num) temp: (struct node * ) malloc(sizeof(struct node)); temp->data=num; list—temp; void insert beg(int num) temp: (struct node* ) malloc( sizeof(struct node) ); temp->data=num;
  4. void insert end(int num) temp: (struct node* ) malloc( sizeof(struct node) ); temp->data=num; list—temp; void insert spec(int pos,int num) struct node *p; int i; for(i=l;idata=num; temp->next=p->next; p->next=temp; void delete beg() int x; struct node *temp; x=temp->data; printf("\n\nDeIeted data: %d\n\n",x); free(temp); void delete end()
  5. struct node *a, * b-NULL; while(a list) b=a; b; int x; list=b; list->next = a->next; printf("\n\nDeIeted data: %d\n\n",x), free(a); void delete spec(int pos) struct node *a, *b; b-NULL; int i; i
  6. printf("%d printf("%d\n\n",a->data); OUTPUT 1: 1.Create 1st node 2.DispIay 3.1nsert 4.Delete Enter your choice: 1 Enter value to be stored in first node: 10 Do you want to repeat? (yes-I) 1.Create 1st node 2.DispIay 3.1nsert 4.Delete Enter your choice: 1.At beggining 2.At end 3 3.At specific position Enter your choice: 2 20 Enter data: Do you want to repeat? (yes-I) 1.Create 1st node 2.DispIay 3.1nsert 4.Delete Enter your choice: 1.At beggining 2.At end 3 3.At specific position Enter your choice: 1 Enter data: 5 Do you want to repeat? (yes-I) 1 1 1
  7. 1.Create 1st node 2.Display 3.1nsert 4.Delete Enter your choice: The list is: 5 10 20 2 Do you want to repeat? (yes-I) OUTPUT 2 : 1.Create 1st node 2.DispIay 3.1nsert 4.Delete Enter your choice: 1 Enter value to be stored in first node: 50 Do you want to repeat? (yes-I) 1.Create 1st node 2.Display 3.1nsert 4.Delete Enter your choice: 1.At beggining 2.At end 3 3.At specific position Enter your choice: 2 60 Enter data: Do you want to repeat? (yes-I) 1 1 1.Create 1st node 2.Display 3.1nsert 4.Delete Enter your choice: 3
  8. 1.At beggining 2.At end 3.At specific position Enter your choice: 1 Enter data: 40 Do you want to repeat? (yes-I) 1.Create 1st node 2.Display 3.1nsert 4.Delete Enter your choice: The list is: 40 50 60 2 Do you want to repeat? (yes-I) 1.Create 1st node 2.DispIay 3.1nsert 4.Delete Enter your choice: 1.From beginning 2.From end 4 3.From specific postion 1 Enter your choice: Deleted data: 40 Do you want to repeat? (yes-I) 1.Create 1st node 2.Display 3.1nsert 4.Delete Enter your choice: The list is: 50 60 2 Do you want to repeat? (yes-I) 1 1 3