#include <iostream>
#include <cmath>
Go to the source code of this file.
◆ divide()
| void divide |
( |
Node *& | head, |
|
|
Node *& | second ) |
Definition at line 49 of file ex6.cpp.
50{
51 if (head == NULL) {
52 second = NULL;
53 return;
54 }
55
57 len = (len-1)/2;
58
59 Node * current = head;
60 for (int i = 0; i < len; ++i)
61 current = current->
next;
62
63
64 second = current->
next;
66
67}
int list_length(Node *head)
References list_length(), and Node::next.
Referenced by main().
◆ list_length()
| int list_length |
( |
Node * | head | ) |
|
Definition at line 41 of file ex6.cpp.
42{
43 int i = 0;
44 for (
Node * current = head; current != NULL; current = current->
next)
45 ++i;
46 return i;
47}
References Node::next.
Referenced by divide().
◆ main()
Definition at line 69 of file ex6.cpp.
70{
71 Node * head = NULL, * tail = NULL;
72 int num = 0;
73
74
75 cout << "input integers (-999 to end): ";
76 cin >> num;
77 while ( num != -999 ) {
79 cin >> num;
80 }
81
82
84
85
86 cout << endl;
91
92 return 0;
93}
void tail_insert(Node *&head, Node *&tail, int num)
void print_list(Node *head)
void divide(Node *&head, Node *&second)
References divide(), print_list(), and tail_insert().
◆ print_list()
| void print_list |
( |
Node * | head | ) |
|
Definition at line 12 of file ex6.cpp.
13{
14 Node * current = head;
15 while (current != NULL)
16 {
17
18 cout << current->
info <<
" -> ";
19 current = current->
next;
20 }
21 cout << "NULL\n";
22}
References Node::info, and Node::next.
Referenced by main().
◆ tail_insert()
| void tail_insert |
( |
Node *& | head, |
|
|
Node *& | tail, |
|
|
int | num ) |
Definition at line 24 of file ex6.cpp.
26{
30
31 if (head == NULL) {
32 head = p;
33 tail = p;
34 }
35 else {
37 tail = p;
38 }
39}
References Node::info, and Node::next.
Referenced by main().