C PROGRAM PLEASE Write a C program containing a linked list of ten integer numbe
ID: 3649816 • Letter: C
Question
C PROGRAM PLEASE Write a C program containing a linked list of ten integer numbers. Have the program display the numbers in the list.Explanation / Answer
#include #include main() { int ch,n,i,key,a[100],k; int bin(); int lin(); do { clrscr(); printf(" ***** MAIN MENU ***** "); printf(" 1. Linear Search "); printf(" 2. Binary Search "); printf(" 3. Exit Program"); printf(" ----------------------------------"); printf(" Select any one of the above==>"); scanf("%d",&ch); switch(ch) { case 1: printf(" Enter the size of the array==>"); scanf("%d",&n); printf(" Enter the array elements "); for(i=0;iitem); if(strcmpi(record->item,"END")==0) record->next=NULL; else { /* allocate space for next node */ record->next=(node*)malloc(sizeof(node)); /* create the next node */ create(record->next); /* note that recursion has been used here */ } return; } /* end of create */ void display(node *record) /* display the linked list */ /* argument points to the current node */ { if(record->next!=NULL) { printf(" %s",record->item); /* display this data item */ display(record->next); /* get the next data item(recursion used) */ } return; } /* end of display */ node *insert(node *first) /* add one component to the linked list */ /* returns pointer to the begining of the modified list */ { node *locate(node *,char[]); /* function declaration */ node *newrecord; /* pointer to new node */ node *tag; /* pointer to node before target node */ char newitem[40]; /* new dataitem */ char target[40]; /* data item following the new entry */ printf(" New data item: "); scanf("%s",newitem); printf(" Place before (type 'END' if last) : "); scanf("%s",target); if(strcmpi(first->item,target)==0) { /* new node is first in line */ /* allocate space for the new node */ newrecord=(node*)malloc(sizeof(node)); /* assign the new data item to newrecord->item */ strcpy(newrecord->item,newitem); /* assign the current pointer to newrecord->next */ newrecord->next=first; /* new pointer becomes the begining of the list */ first=newrecord; } else { /* insert new node after an existing node */ /* locate the node preceding the target node */ tag=locate(first,target); if(tag==NULL) printf(" Match not found - Please try again "); else { /* allocate space for the new node */ newrecord=(node*)malloc(sizeof(node)); /* assign the new data item to newrecord->item */ strcpy(newrecord->item,newitem); /* assign the next pointer to newrecord->next */ newrecord->next=tag->next; /* assign the new pointer to tag->next */ tag->next=newrecord; } } return(first); } node *locate(node *record,char target[]) /* locate a node */ /* return a pointer to the node before the target node first argument points to the current node second argument is the target string */ { if(strcmpi(record->item,target)==0) /* found a match */ return(record); else if(record->next->next==NULL) return(NULL); /* end of list */ else locate(record->next,target); /* try next node (recursion) */ } node *del(node *first) /* delete one component from the linked list return pointer to begining of of modified list. argument points to the first node. */ { node *locate(node *,char[]); /* function declatration */ node *tag; /* pointer to node before target node */ node *temp; char target[40]; /* data item to be deleted */ printf("Data item to be deleted: "); scanf("%s",target); if(strcmpi(first->item,target)==0) { /* delete the first node */ /* mark the node following the target node */ temp=first->next; /* free space for the target node */ free(first); /* adjust the pointer to the first node */ first=temp; } else /* delete a data item other then the first */ /* locate the node preceding the target node */ tag=locate(first,target); if(tag==NULL) printf(" Match not found - Please try again "); else { /* mark the node following the target node */ temp=tag->next->next; /* free space for the target node */ free(tag->next); /* adjust the link to the next node */ tag->next=temp; } return(first); } /*20. Write a C program to create a subdirectory if it does not exist, using DOS interrupts.A suitable message should be displayed on CRT depending on the success or failure of operation */ #include #include union REGS inregs,outregs; char newdir[10]; void main() { printf(" Enter New Directory Name:"); scanf("%s",&newdir); inregs.x.dx=(int) &newdir; /* DOS function 39H is used to create subdir */ inregs.h.ah=0x39; /* inregs.h.ah specifies the DOS function to be envoked */ intdos(&inregs,&outregs); /* intdos() executes DOS interrupt INT 21H */ if(outregs.x.cflag!=0) /* carry flag is set if an error occurs */ printf(" Error! New Directory %s could not be created",newdir); else printf(" New Directory %s was created in current directory",newdir); } /* Note: After the INT 21H returns it copies the current registers and flags value to there corresponding fields in outregs */ Useful Links to C/C++ Contents Previous Page © Copyrights Madhu Sudan Rao G.K [CodeEverywhere.Com]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.