-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.cpp
More file actions
79 lines (58 loc) · 1.26 KB
/
4.cpp
File metadata and controls
79 lines (58 loc) · 1.26 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <list>
using namespace std;
int main()
{
cout << "Bidirectional linked list: " << endl;
list<int> nums = { 3,1,5,9,2,6,4,7,8 };
cout << "list: ";
for (int el : nums)
{
cout << el << " ";
}
cout << "\n\nAfter sorting:" << endl;
list<int> sorted_nums;
list<int> temp_nums;
int size = nums.size();
while (sorted_nums.size() != size) {
int max = nums.front();
while (nums.size() != 0) {
if (nums.front() > max) {
max = nums.front();
}
temp_nums.push_back(nums.front());
nums.pop_front();
}
while (temp_nums.size() != 0) {
if (temp_nums.front() == max) {
sorted_nums.push_back(temp_nums.front());
temp_nums.pop_front();
}
else {
nums.push_back(temp_nums.front());
temp_nums.pop_front();
}
}
}
for (int el : sorted_nums)
{
nums.push_front(el);
}
cout << "list: ";
for (int el : nums)
{
cout << el << " ";
}
int k = 5;
cout << "\n\nTry to find "<< k <<" in list: " << endl;
int index = 0;
for (int el : nums)
{
if (el == k) {
cout << "k="<< 5 <<" founded of index " << index << endl;
return 0;
}
index++;
}
cout << "Not founded" << endl;
}