Question: First test sample code fig12_03.c and then add two functions described below in the sample code and test the new program. Your testing result would

First test sample code fig12_03.c and then add two functions described below in the sample code and test the new program. Your testing result would be like the following.

Concatenate the current linked list with a built-in list X->Y->Z.

Merge the current list with a built-in list A->C->E into a single ordered list.

here is the fig12_03:

#include #include

struct listNode{ char data; struct listNode *nextPtr; }; typedef struct listNode ListNode; typedef ListNode* ListNodePtr; void insert(ListNodePtr *sPtr,char value); char delete(ListNodePtr *sPtr,char value); int isEmpty(ListNodePtr sPtr); void printList(ListNodePtr currentPtr); void instructions(void);

int main(void) { ListNodePtr startPtr=NULL; char item; instructions();//displays main menu printf("%s","?"); unsigned int choice; scanf("%u",&choice); while(choice!=3) { switch(choice) { case 1: printf("%s","enter a character: "); scanf(" %c",&item); insert(&startPtr,item); printList(startPtr); break; case 2: if(!isEmpty(startPtr)) { printf("%s","Enter character to be deleted: "); scanf(" %c",&item); if(delete(&startPtr,item)) { printf("%c deleted ",item); printList(startPtr); } else{ printf("%c not found ",item); } } else{ puts("list is empty "); } break; default: puts("invalid choice "); instructions(); break; } printf("%s","?"); scanf("%u",&choice); } puts("end of run"); }

void instructions(void) { puts("enter your choice:"); puts("1 to insert an element into the list"); puts("2 to delete an element from the list"); puts("e to end:"); } //insert a new value into the list in sorted value void insert(ListNodePtr *sPtr,char value) { ListNodePtr newPtr=malloc(sizeof(ListNode)); if(newPtr!=NULL) { newPtr->data=value; newPtr->nextPtr=NULL; ListNodePtr previousPtr=NULL; ListNodePtr currentPtr=*sPtr; while(currentPtr!=NULL && value>currentPtr->data) { previousPtr=currentPtr; currentPtr=currentPtr->nextPtr; } if(previousPtr==NULL) { newPtr->nextPtr=*sPtr; *sPtr=newPtr; } else { previousPtr->nextPtr=newPtr; newPtr->nextPtr=currentPtr; } } else { printf("%c not inserted.No memory available. ",value); } } char delete(ListNodePtr *sPtr,char value) { if(value==(*sPtr)->data) { ListNodePtr tempPtr=*sPtr; *sPtr=(*sPtr)->nextPtr; free(tempPtr); return value; } else { ListNodePtr previousPtr=*sPtr; ListNodePtr currentPtr=(*sPtr)->nextPtr; while(currentPtr!=NULL && currentPtr->data!=value) { previousPtr=currentPtr; currentPtr=currentPtr->nextPtr; } if(currentPtr!=NULL) { ListNodePtr tempPtr=currentPtr; previousPtr->nextPtr=currentPtr->nextPtr; free(tempPtr); return value; } } return'\0'; } int isEmpty(ListNodePtr sPtr) { return sPtr==NULL; } void printList(ListNodePtr currentPtr) { if(isEmpty(currentPtr)) { puts("list is empty"); } else puts("the list is :"); while(currentPtr!=NULL) { //printf(currentPtr!=NULL) { printf("%c--> ",currentPtr->data); currentPtr=currentPtr->nextPtr; } } puts("NULL "); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!