123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
void create (node *&head, node *&temp, node *&tail) { int sk; cout << "Irasykite norima skaiciu " << endl; cin >> sk; temp = new node; temp->data = sk; temp->next = NULL; if (head == NULL) { temp->prev = NULL; head = temp; } else { tail = head; while (tail->next != NULL) { tail = tail->next; } tail->next = temp; temp->prev = tail; } } void print(node *&head, node *&temp, node *&tail) { if (head == NULL) { cout << "Sarasas tuscias" << endl; return; } temp = head; while (temp != NULL) { cout << temp->data << endl; temp = temp->next; } } void print_bakcwards(node *&head, node *&temp, node *&tail) { if (head == NULL) { cout << "Sarasas tuscias" << endl; return; } temp = tail; while (temp != NULL) { cout << temp->data << endl; temp = temp->prev; } }
tail
create()
12
temp = ... // a node is created and its values set head = temp;
123
// 1. make list point to the last node // 2. tail->next = temp;
tail=temp;