Operation place insert an element x into sorted linear linked list structure. Where head points to a sorted list and x is an element to be inserted into its proper position within the list.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 21SA
icon
Related questions
Question
100%

Please modify this Code if x was char not int .. thank you 

( with explanation for each line if possible) many thanks.

 

Operation place insert an element x into sorted linear linked list structure.
Where head points to a sorted list and x is an element to be inserted into its
proper position within the list.
void place(NODEPTR *head , int x)
{
NODEPTR p, q;
q= NULL;
for(p=*head; p!=NULL && x>p->info; p=p->next)
q= p;
if (q == NULL) /* insert x at the head of the list */
{p=getnode()
p->info=x;
p->next = head;
head=p;
}
Else{
p=getnode();
p->info=x;
p->next=q->next;
q->next=p;
}
}
Transcribed Image Text:Operation place insert an element x into sorted linear linked list structure. Where head points to a sorted list and x is an element to be inserted into its proper position within the list. void place(NODEPTR *head , int x) { NODEPTR p, q; q= NULL; for(p=*head; p!=NULL && x>p->info; p=p->next) q= p; if (q == NULL) /* insert x at the head of the list */ {p=getnode() p->info=x; p->next = head; head=p; } Else{ p=getnode(); p->info=x; p->next=q->next; q->next=p; } }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
C-string
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning