Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that initializes the String array as follows (String is an array

ID: 3691971 • Letter: W

Question

Write a program that initializes the String array as follows (String is an array of pointers) String[0] = “Abbie”, String[1] = “Oakley”, String[2] = “Sylvia”, String[3] = “Uwe”, String[4] = “Ken”, String[5] = “Aaron”, String[6] = “Fabien”. Your program also initializes a linked list to be empty. Then the program takes the strings from the array one by one, starting from element index 0, and inserts the string in the linked list. The string should be inserted in the right location, so as to maintain the lexicographic order. The complete content of the linked list is printed after every insertion, with the elements being printed in the order they appear in the list. Finally, after all the array elements are inserted, the program should print again the complete content of the linked list, with the elements being printed in the order they appear in the list. If your program is correct, the order in which the strings are printed should be: Aaron, Abbie, Fabien, Ken, Oakley, Sylvia, Uwe.
1. Requirements
To ensure consistency in the submissions, your program must do the following:
1 – Use this self referential structure struct studentRecord // Self referential structure used in linked list

{ char name[NAME_LENGTH+1]; struct studentRecord * nextPtr; };

// Function prototypes
/**********************************************************/ /* Insert newName into the linked list pointed by *sPtr Walks through the list to find the right location for insertion Insertion is done in lexicographic order of the student's name Note: sPtr is a pointer to a pointer, and *sPtr points to the first Student of the list, or is NULL if the list is empty */ /**********************************************************/ void insert(studPtr *sPtr, char * newName);
/**********************************************************/ /* Searches for Student in the list by name and deletes it If student not found, return 0. Else, if deletion successful, return 1*/ /**********************************************************/ int delete(studPtr *sPtr, Student myStud);
/**********************************************************/ /* Print the Student pointed by myPtr /**********************************************************/ void printStudent(studPtr myPtr);
/**********************************************************/ /* Prints the elements of the linked list pointed by myPtr */ /**********************************************************/ void printList(studPtr myPtr);
For the extra credit: /**********************************************************/ /* Displays the menu and returns the user's choice as an int */ /**********************************************************/ int getUserChoice();

Explanation / Answer

Answer for Question:

This below C++ code will help or solved the given problem statement.

1. Created the linked list with Strings and nodes

2. This below code will maintain the nodes order in lexical oredr.

3. See the code below..

#include <iostream>
#include <string>

struct Node
{
std::string word;
struct Node *next;
};

Node *add_node( struct Node *list, const std::string &s )
{
struct Node *prev = NULL;
struct Node *current = list;

while ( current && !( s < current->word ) )
{
prev = current;
current = current->next;
}

if ( prev == NULL )
{
list = new Node { s, list };
}
else
{
prev->next = new Node { s, prev->next };
}

return list;
}

void print_list( const struct Node *list )
{
for ( ; list != NULL; list = list->next ) std::cout << list->word << ' ';
}

int main()
{
struct Node *list = NULL;

// for ( const std::string &s : { "B", "X", "A", "C", "F", "G" } )
for ( const char *s : { "Aaron", "Abbie", "Fabien", "Ken", "Oakley", "Sylvia", "Uwe" } )
{
list = add_node( list, s );
}

print_list( list );
std::cout << std::endl;

return 0;
}

Output:

Aaron Abbie Fabien Ken Oakley Sylvia Uwe

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote