COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
build_list_forward.cpp File Reference
#include <iostream>
Include dependency graph for build_list_forward.cpp:

Go to the source code of this file.

Classes

struct  Node
 

Functions

int main ()
 
void print_list (Node *head)
 
void tail_insert (Node *&head, Node *&tail, int num)
 

Function Documentation

◆ main()

int main ( void )

Definition at line 42 of file build_list_forward.cpp.

43{
44 Node * head = NULL, * tail = NULL;
45 int num = 0;
46
47 // build linked list backward
48 cout << "input integers (-999 to end): ";
49 cin >> num;
50 while ( num != -999 ) {
51 tail_insert(head, tail, num);
52 cin >> num;
53 }
54
55 // print the items in the linked list
56 print_list(head);
57
58 return 0;
59}
void tail_insert(Node *&head, Node *&tail, int num)
void print_list(Node *head)
Definition 3.cpp:6

References print_list(), and tail_insert().

Here is the call graph for this function:

◆ print_list()

void print_list ( Node * head)

Definition at line 11 of file build_list_forward.cpp.

12{
13 Node * current = head;
14 while (current != NULL)
15 {
16 // process the current node, e.g., print the content
17 cout << current->info << " -> ";
18 current = current->next;
19 }
20 cout << "NULL\n";
21}
int info
Definition ex4ex5.cpp:7
Node * next
Definition ex4ex5.cpp:8

References Node::info, and Node::next.

Referenced by main().

Here is the caller graph for this function:

◆ tail_insert()

void tail_insert ( Node *& head,
Node *& tail,
int num )

Definition at line 23 of file build_list_forward.cpp.

25{
26 Node * p = new Node;
27 p->info = num;
28 p->next = NULL;
29
30 if (head == NULL) {
31 head = p;
32 tail = p;
33 }
34 else {
35 tail->next = p;
36 tail = p;
37 }
38}

References Node::info, and Node::next.

Referenced by main().

Here is the caller graph for this function: