-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
47 lines (42 loc) · 777 Bytes
/
Copy pathtest.cpp
File metadata and controls
47 lines (42 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using std::cout;
using std::endl;
struct Node
{
int key = 0;
Node* next = nullptr;
};
void push_back(Node*& head_ref, int new_key)
{
Node* new_node = new Node{new_key, nullptr};
if (head_ref == nullptr)
{
head_ref = new_node;
return;
}
Node* ptr = head_ref;
while (ptr->next != nullptr)
{
ptr = ptr->next;
}
ptr->next = new_node;
}
void print_list(Node* head_ref)
{
Node* current = new Node;
current = head_ref;
while(current != nullptr)
{
cout << " " << current->key;
current = current->next;
}
cout << endl;
}
int main() {
Node* HEAD = nullptr;
push_back(HEAD, 0);
push_back(HEAD, 1);
push_back(HEAD, 2);
print_list(HEAD);
return 0;
}