So my question is say i have a linked list with 10 nodes, how would i print a specific node . In this case, i need to print whichever node(1 through 10) that the user asks for. Im just kind of confused as to what i should do. Any help is appreciated, maybe i can figure it out in the meantime. Thanks
#include <iostream>
using namespace std;
int main()
{
int x = 5;
for ( int r = 0; r < x; r++ )
{
for ( int c = 0; c < x; c++ )
{
if ( c == 0 || c == x - 1 || r == 0 || r == x - 1)
cout << "*";
else
cout << " ";
}// inner for
cout << endl;
}// outer for
}
Using while loop, modify the program and x is hard-coded and the program in Table 1 executes only once. How do i amend the program to allow data entry for the variable x and repeats the execution until the user enters the sentinel value, -1 to exit the program.
@Nicholas001
Create a new thread for that and you'll be much more likely to receive help.
(Oh, and don't forget to put your code in [code] [/code] tags.)
@bbunn77
Yeah, basically just something like
1 2 3 4 5
Node* it = head_of_list;
for (int i = 1; i < which_node; ++i) // You *did* say 1-10, not 0-9, right?
it = it->next_node;
// Now print contents of the 'it' node
(Obviously, replace "Node", "head_of_list", "which_node", and "next_node" with the appropriate names).