Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Lab 9

Lab 9

Ratings: (0)|Views: 16|Likes:
Published by Sandeep V Gowda
Data Structures Lab Program 9, VTU
Data Structures Lab Program 9, VTU

More info:

Published by: Sandeep V Gowda on Nov 12, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

11/12/2010

pdf

text

original

 
9.Write a C Program using dynamic variables and pointers, toconstruct a singly linked list consisting of the followinginformation in each node: student id (integer), student name(character string) and semester (integer). The operations tobe supported are:a. The insertion operation1. At the front of a list2. At the back of the list3. At any position in the listb. Deleting a node based on student id. If the specified nodeis not present in the list an error message should bedisplayed. Both the options should be demonstrated.c. Searching a node based on student id and update the info.content. If the specified node is not present in the listan error message should be displayed. Both situations shouldbe displayed.d. Displaying all the nodes in the list.PROGRAM
#include<stdio.h>#include<conio.h>#include<process.h>#include<string.h>void ins_front();void ins_end();void ins_pos();void del();void search();void display();struct NODE{int id,sem;char name[10];struct NODE *link;};typedef struct NODE node;node *start=NULL,*temp,*new1,*cptr,*prev;int i,choice;char ch;void main(){clrscr();do{printf("1:ins_front 2:ins_end 3:ins_pos 4:delete 5:search 6:display\n");printf("enter ur choice\n");scanf("%d",&choice);switch(choice){case 1:ins_front();break;case 2:ins_end();break;
 
case 3:ins_pos();break;case 4:del();break;case 5:search();break;case 6:display();break;}printf("do u want to continue\n");fflush(stdin);scanf("%c",&ch);}while(ch=='y');getch();}void ins_front(){new1=(node*) malloc(sizeof(node));printf("enter student id,name,sem\n");scanf("%d%s%d",&new1->id,new1->name,&new1->sem);if(start==NULL){new1->link=NULL;start=new1;}else{new1->link=start;start=new1;}//return(0);}void ins_end(){new1=(node*) malloc(sizeof(node));printf("enter student id,name,sem\n");scanf("%d%s%d",&new1->id,new1->name,&new1->sem);if(start==NULL){new1->link=NULL;start=new1;}temp=start;while(temp->link!=NULL){temp=temp->link;}temp->link=new1;new1->link=NULL;//return(0);}void ins_pos(){int pos,count;
 
new1=(node*) malloc(sizeof(node));printf("enter student id,name,sem\n");scanf("%d%s%d",&new1->id,new1->name,&new1->sem);printf("enter the position to be insert\n");scanf("%d",&pos);if(pos==1){new1->link=start;start=new1;}count=2;prev=start;temp=start->link;while(count<pos && temp!=NULL){prev=temp;temp=temp->link;count++;}new1->link=temp;prev->link=new1;//return(0);}void del(){int key;printf("enter the student id to be delete\n");scanf("%d",&key);if(start->id==key){temp=start;start=start->link;free(temp);}prev=start;temp=start->link;while(temp!=NULL && temp->id!=key){prev=temp;temp=temp->link;}if(temp==NULL){printf("student with that id does not exist\n");//return 0;}prev->link=temp->link;}void search(){int key;printf("enter the student id to be search\n");scanf("%d",&key);

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->