>I am trying to make sure I am understanding what I am reading.
The best way to check your understanding is to write a small program that tests your assumptions:
Code:
/* Ugly quick code */
#include <iostream>
using namespace std;
struct node {
int data;
node *next;
node(int init, node *link)
: data(init)
, next(link)
{}
};
int
main()
{
node *head, *tail;
head = new node(0, 0);
head->next = head;
tail = head;
for (int i = 1; i < 10; i++) {
tail->next = new node(i, head);
tail = tail->next;
}
for (tail = head; tail->next != head; tail = tail->next) {
cout<< tail->data <<endl;
}
cout<< tail->data <<endl<<endl;
node *cur = tail->next;
tail->next = cur->next;
for (tail = head; tail->next != head; tail = tail->next) {
cout<< tail->data <<endl;
}
cout<< tail->data <<endl;
}
This clearly doesn't work when you run it. The problem is that tail->next will never point to head because head is the node that was removed from the list. You need to reseat head too:
Code:
node *cur = tail->next;
tail->next = cur->next;
head = tail->next;