How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Ingo U Your Own Question
Ingo U
Ingo U, Software Engineer
Category: Programming
Satisfied Customers: 755
Experience:  Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
44076068
Type Your Programming Question Here...
Ingo U is online now

I have this linked list in c++ and i would like to know how

Resolved Question:

I have this linked list in c++ and i would like to know how to delete the middle node and link the 1st node to the 3rd node so the values can be printed out:
#include
using namespace std;
struct Node {
string str;
Node *next;
};
int main() {
string entry;
Node *root;
Node *trav;
root = new Node;
cout <> entry;
cout < str = entry;
trav = root;
trav -> next = new Node;
trav = trav -> next;
cout <> entry;
cout < str = entry;
trav -> next = new Node;
trav = trav -> next;
cout <> entry;
cout < str = entry;
trav -> next = NULL;
trav = root;
while(trav != NULL) {
cout < str < next;
}
// code here
while(trav != NULL) {
cout < str < next;
}
cout << endl;
return 0;
}
Submitted: 2 years ago.
Category: Programming
Expert:  Ingo U replied 2 years ago.
Hello again,
how general of a solution do you need?
- Will the list have exactly 3 nodes, no more no less?
- How to identify the node to delete? Only by its position, #2 ?
The steps needed are slightly different for the first node of a list vs. the last node vs. any node in between.
Can you upload your latest code for me to start with, please? Pasting code into this web site doesn't work well as you can see above.
Thanks,
Ingo
Customer: replied 2 years ago.

There are 3 nodes. I'd like to know how to remove the 2nd node, the 1st node and the 3rd node: http://pastebin.com/28Z8CGFw

Expert:  Ingo U replied 2 years ago.
Here's the code:
https://www.dropbox.com/s/j9zddpmc7ksmn2b/LinkedList.cpp?dl=0
As you'll see you have to uncomment one of the 3 blocks of code to delete 1st, 2nd or 3rd node.
Ingo U and other Programming Specialists are ready to help you