Question
Well documented program, telling me what the program is supposed to do.The style should be the one either used in class or by the book
Well documented program, telling me what the program is supposed to do.The style should be the one either used in class or by the book (that is loops designs, explicit choice of variable names, well defined CONSTANT). Avoid using numbers where you can use named constant.Your code should be clear and easy to follow, your main function should be as simple as possible.The following program creates a linked list with three names:
#include
#include
using namespace std;
struct Node
{
string name;
Node *link;
};
typedef Node* NodePtr;
int main(int argc, char** argv) {
NodePtr listPtr, tempPtr;
listPtr = new Node;
listPtr->name = "Emily";
tempPtr = new Node;
tempPtr-> name = "James";
listPtr->link = tempPtr;
tempPtr->link = new Node;
tempPtr = tempPtr->link;
tempPtr -> name = "Joules";
tempPtr -> link = NULL;
//do your work here.
return 0;
}
Add code to the main function that:
- Outputs in order all names in the list.
That is you should have something like:
Emily
James
Joules
- Insert the name Joshua in the list after James then outputs the modified list.
That is you should have something like:
Emily
James
Joshua
Joules
- Delete the node with Joules then outputs the modified list.
That is you should get something like
Emily
James
Joshua
- Deletes all nodes in the list.
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