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

Go to the source code of this file.

Classes

struct  Node
 

Functions

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

Function Documentation

◆ head_insert()

void head_insert ( Node *& head,
int num )

Definition at line 23 of file build_list_backward.cpp.

24{
25 Node * p = new Node;
26 p->info = num;
27 p->next = head;
28 head = p;
29}
Definition 3.cpp:6
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:

◆ main()

int main ( void )

Definition at line 32 of file build_list_backward.cpp.

33{
34 Node * head = NULL;
35 int num = 0;
36
37 // build linked list backward
38 cout << "input integers (-999 to end): ";
39 cin >> num;
40 while ( num != -999 ) {
41 head_insert(head, num);
42 cin >> num;
43 }
44
45 // print the items in the linked list
46 print_list(head);
47
48 return 0;
49}
void head_insert(Node *&head, int num)
void print_list(Node *head)

References head_insert(), and print_list().

Here is the call graph for this function:

◆ print_list()

void print_list ( Node * head)

Definition at line 11 of file build_list_backward.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}

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

Referenced by main().

Here is the caller graph for this function: