Hi There, this is my code
my friend add these following lines into my code:Code:#include <iostream>
#include <string>
using namespace std;
struct node
{
string data;
node *nxt;
};
node *start_ptr = NULL;
node *current;
void add_node_at_end()
{
node *temp, *temp2;
temp = new node;
cout << "Please enter any data: ";
cin >> temp->data;
temp->nxt = NULL;
if (start_ptr == NULL)
{
start_ptr = temp;
current = start_ptr;
}
else
{
temp2 = start_ptr;
while (temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;
}
}
void display_list()
{
node *temp;
temp = start_ptr;
cout << endl;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL)
{
// Display details for what temp points to
cout << "Data : "<<temp->data;
cout << endl;
current = current->nxt;
temp = temp->nxt;
}
cout << "<- Current node"<<"\n";
cout << "End of list!" << endl;
}
}
void main()
{
int i;
for (i=0; i<5; i++)
add_node_at_end();
display_list();
}
What actually will the code above do ??Code:temp2 = start_ptr;
while (temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;