-
Notifications
You must be signed in to change notification settings - Fork 0
/
test22.cpp
65 lines (60 loc) · 1.09 KB
/
test22.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<ctype.h>
using namespace std;
struct Node {
int val;
Node* next;
Node(int n, Node* next_ = nullptr) :
val(n), next(next_) {}
};
void addNode(Node* head, int n)
{
Node* p = head;
Node* newNode = new Node{ n, nullptr };
while (p->next)
{
p = p->next;
}
newNode->val = n;
newNode->next = nullptr;
p->next = newNode;
}
Node* crateList()
{
Node* list = new Node{ -1, nullptr };
for (int i = 1; i < 10; i++)
{
//addNode(list, rand() % 10 + '0');
//addNode(list, rand() % 26 + 'a');
}
return list;
}
void printNode(Node* head)
{
Node* p = head->next;
while (p)
{
std::cout << p->val << ' ';
p = p->next;
}
std::cout << endl;
}
int main()
{
Node list{-1};
vector<int> a;
int n = 0;
cin >> n;
while ( n != 0)
{
a.push_back(n);
cin >> n;
}
sort(a.begin(), a.end());
for (int i = 0; i < a.size(); i++)
addNode(&list, a[i]);
printNode(&list);
}