Create a structure that has one variable called value and one pointer to the lis
ID: 3648754 • Letter: C
Question
Create a structure that has one variable called value and one pointer to the list (making it a linked list). Prompt for 5 values from the keyboard as input and store them in the linked list. Print out the current contents of the list. Allow the user to add one more value to the linked list, and print the contents of the list again.Explanation / Answer
#include #include #include struct ListNode{ int value; struct ListNode *link; }; int main() { struct ListNode *head=NULL; struct ListNode *temp,*last; struct ListNode *myIterator; int i; for(i=0;ivalue)); temp->link = NULL; if(head == NULL) { last =head = temp; }else { last ->link = temp; last = temp; } } temp = head; printf("Value in list are :"); while(temp!=NULL) { printf(" %d ",temp->value); temp = temp ->link; } printf(" "); temp=malloc(sizeof(struct ListNode)); printf("Adding new num in the list , enter num :"); scanf("%d",&(temp->value)); temp->link = NULL; if(head == NULL) { last =head = temp; }else { last ->link = temp; last = temp; } printf("Value in list after insertion are :"); temp =head; while(temp!=NULL) { printf(" %d ",temp->value); temp = temp ->link; } printf(" "); printf(" "); system("pause"); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.