Question
(C++ DATA STRUCTURE) QUESTION: Show the data structure for a method that allows the user to place a new node at a specific location in
(C++ DATA STRUCTURE)
QUESTION: Show the data structure for a method that allows the user to place a new node at a specific location in a list.
************************************************* USE DATA STRUCTURE TO MAKE A GRAPHICAL REPRESENTATION OF YOUR SOLUTION AND ANSWER THE QUESTION, IS NOT ONLY ABOUT THE CODE, BUT ALSO ABOUT ILLUSTRATION. *************************************************
CODE BELOW:
LISTREC * InsertAt(LISTREC *liststart, ENTRY newentry, int n)
{
int i = 0;
//LISTREC * liststart;
LISTREC * last = NULL;
LISTREC * next = liststart;
if (liststart == NULL)
{
liststart = (LISTREC*)malloc(sizeof(LISTREC)); /*creates new node*/
liststart->info=newentry;
liststart->link = NULL;
printf(" Created node at %d",i);
}//if
else while ((next->link != NULL) && (i != n))
{
last = next;
next = next->link;
++i;
}//else while
if (next == NULL)
{
next = (LISTREC*)malloc(sizeof(LISTREC)); /*creates new node*/
next->info=newentry;
next->link = NULL;
printf(" Created node at %d",i);
}//if
else if (i==n)
{
last->link = (LISTREC*)malloc(sizeof(LISTREC)); /*creates new node*/
last->link->info=newentry;
last->link->link = next;
printf(" Created node at %d",i);
}//else
return liststart;
}// insertAT
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started