1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
#include <iostream> #include <cstdlib> #include <cassert> using namespace std; struct nodeType { int info; nodeType *link; }; void printList(nodeType *first); void append(nodeType * first, int x); int main() { int x; nodeType *head = NULL; cout << "Enter some ints - terminate with control-Z "<< endl; while (cin >> x) append(head, x); cout << endl; printList(head); system("pause"); return EXIT_SUCCESS; } void append(nodeType * first, int x) { // append a node containing x to // the end of the list first nodeType *temp = new nodeType; temp ->info = x; temp->link = NULL; if (first == NULL) first = temp; else { nodeType *p = first; assert (p != NULL); while(p != NULL) p = p -> link; p->link = temp; } } void printList(nodeType *first) { // displays the list // pointed to by first nodeType *current = first; while (current != NULL) { cout << current->info << " "; current = current->link; } cout << endl; }
(p->link != NULL)
12
void printList(nodeType *first); void append(nodeType * first, int x);
void printList(nodeType **first); void append(nodeType ** first, int x);
printList
void append(nodeType *& first, int x);