Help please!!!!! Create a linked list structure to implement a stack and alsocre
ID: 3615198 • Letter: H
Question
Help please!!!!! Create a linked list structure to implement a stack and alsocreate a linked list structure to implement a queue.To demonstrate that the stack is working correctly, write a smallfunction using a stack that will determine if a given input stringis a valid tag.
To test the queue, ask the user for input until they enter a -1.For each integer they give you, if it is odd, enqueue it in onequeue, if it is even, enqueue it in another queue. After a -1 hasbeen entered, display first the even numbers entered, and then theodd numbers.
Help please!!!!! Create a linked list structure to implement a stack and alsocreate a linked list structure to implement a queue.
To demonstrate that the stack is working correctly, write a smallfunction using a stack that will determine if a given input stringis a valid tag.
To test the queue, ask the user for input until they enter a -1.For each integer they give you, if it is odd, enqueue it in onequeue, if it is even, enqueue it in another queue. After a -1 hasbeen entered, display first the even numbers entered, and then theodd numbers.
Explanation / Answer
# include# includestruct node{int info;struct node *link;} *top=NULL;struct list{char data;struct list *next;};typedef struct list node;void qinsert(node**,node**); /** Inserting character function in queue **/void qdelete(node**,node**); /** Deleting character function in queue **/void disp(node*); /** Output displaying function **/void qinsert(node **front,node **rear){node *newnode; /* New node to be inserted */newnode=(node*)malloc(sizeof(node));newnode->next=NULL;printf(" Enter the character to push ");fflush(stdin);scanf("%c",&(newnode->data));if(*front==NULL && *rear==NULL){*front=newnode;*rear=newnode;}else{(*rear)->next=newnode;*rear=newnode;}}void qdelete(node **front,node **rear){node *delnode; /* Node to be deleted */if((*front)==NULL && (*rear)==NULL)printf(" Queue is empty to delete any element ");else{delnode=*front;(*front)=(*front)->next;free(delnode);}}void disp(node *f){while(f!=NULL){printf(" %c ",f->data);f=f->next;}}main(){int choice;int opt; /* Option inputing variable */ char ch; /* choice inputing variable */ node *front; /* front pointer in queue*/ node *rear; /* rear pointer in queue */rear=front=NULL;while(1){ printf("1.Push ");printf("2.Pop ");printf("3.Display ");printf(" Queue operations: ");printf("4.Insert ");printf("5.delete ");printf("6.Display the list ");printf("7.Quit ");printf("Enter your choice : ") ;scanf("%d", &choice);switch(choice){case 1:push();break;case 2:pop();break;case 3:display();break;case 7:exit(1);case 4:qinsert(&front,&rear);break;case 5:qdelete(&front,&rear);break;case 6:disp(front);break;default :printf("Wrong choice ");}/*End of switch */}/*End of while */}/*End of main() */push(){struct node *tmp;int pushed_item;tmp = (struct node *)malloc(sizeof(struct node));printf("Input the new value to be pushed on the stack : ");scanf("%d",&pushed_item);tmp->info=pushed_item;tmp->link=top;top=tmp;}/*End of push()*/pop(){struct node *tmp;if(top == NULL)printf("Stack is empty ");else{ tmp=top;printf("Popped item is %d ",tmp->info);top=top->link;free(tmp);}}/*End of pop()*/display(){ struct node *ptr;ptr=top;if(top==NULL)printf("Stack is empty ");else{printf("Stack elements : ");while(ptr!= NULL){printf("%d ",ptr->info);ptr = ptr->link;}/*End of while */}/*End of else*/}/*End of display()*/Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.