Answer the question
In order to leave comments, you need to log in
How to work with singly-directed lists?
There is a structure.
struct listNode {
int key;
int data;
listNode *next;
};
listNode *head;
listNode *tail;
void addItem() {
listNode *currItem = new listNode;
cout << "Enter key: "; cin >> currItem->key; cout << endl;
cout << "Enter data: "; cin >> currItem->data; cout << endl;
currItem->next = NULL;
if (head != NULL) {
tail->next = currItem;
tail = currItem;
}
else head = tail = currItem;
}
tail->next = currItem;
tail = currItem;
Answer the question
In order to leave comments, you need to log in
We have two auxiliary structures - a structure that stores the first element of the list (in order to know where to start) and a structure for storing the last element (I don’t quite understand why).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question