-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorting.html
98 lines (75 loc) · 9.57 KB
/
sorting.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>Algorithm and Complexity</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div id="links">
<a class="social facebook" href="#"><img src="images/facebook.png"></a>
<a class="social vk" href="#"><img src="images/vk.png"></a>
<a class="social twitter" href="#"><img src="images/twitter.png"></a>
</div>
<div id="main">
<div id="nav">
<ul>
<li><a href="index.html">Main •</a></li>
<li><a href="myvector.html">MyVector •</a></li>
<li><a href="bubble.html">Bubble Sort •</a></li>
<li><a href="merge.html">Merge Sort •</a></li>
<li><a href="insert.html">Insert Sort •</a></li>
<li><a href="quick.html">Quick Sort •</a></li>
<li><a href="graphs.html" style="color:red;">Graphs •</a></li>
<li><a href="olsen.html">Olsen Gang</a></li>
</ul>
</div>
<div id="border"></div>
<div id="bubble">
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #557799">#include <iostream></span>
<span style="color: #557799">#include <ctime></span>
<span style="color: #557799">#include <cstdlib></span>
<span style="color: #008800; font-weight: bold">using</span> <span style="color: #008800; font-weight: bold">namespace</span> std;
<span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">bubble_sort</span>(<span style="color: #333399; font-weight: bold">int</span> ar[],<span style="color: #333399; font-weight: bold">int</span> length){
<span style="color: #333399; font-weight: bold">bool</span> ready<span style="color: #333333">=</span><span style="color: #007020">false</span>;
<span style="color: #008800; font-weight: bold">while</span>(ready<span style="color: #333333">==</span><span style="color: #007020">false</span>){
ready<span style="color: #333333">=</span><span style="color: #007020">true</span>;
<span style="color: #008800; font-weight: bold">for</span>(<span style="color: #333399; font-weight: bold">int</span> x<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">0</span>;x<span style="color: #333333"><</span>length<span style="color: #333333">-</span><span style="color: #0000DD; font-weight: bold">1</span>;x<span style="color: #333333">++</span>){
<span style="color: #008800; font-weight: bold">if</span>(ar[x]<span style="color: #333333">></span>ar[x<span style="color: #333333">+</span><span style="color: #0000DD; font-weight: bold">1</span>]){
ready<span style="color: #333333">=</span><span style="color: #007020">false</span>;
<span style="color: #333399; font-weight: bold">int</span> temp<span style="color: #333333">=</span>ar[x];
ar[x]<span style="color: #333333">=</span>ar[x<span style="color: #333333">+</span><span style="color: #0000DD; font-weight: bold">1</span>];
ar[x<span style="color: #333333">+</span><span style="color: #0000DD; font-weight: bold">1</span>]<span style="color: #333333">=</span>temp;
}
}
}
}
<span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">display</span>(<span style="color: #333399; font-weight: bold">int</span> ar[],<span style="color: #333399; font-weight: bold">int</span> length){
<span style="color: #008800; font-weight: bold">for</span>(<span style="color: #333399; font-weight: bold">int</span> x<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">0</span>;x<span style="color: #333333"><</span>length;x<span style="color: #333333">++</span>){
cout<span style="color: #333333"><<</span>ar[x]<span style="color: #333333"><<</span>endl;
}
}
<span style="color: #008800; font-weight: bold">inline</span> <span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">mySleep</span>(<span style="color: #333399; font-weight: bold">clock_t</span> sec)
{
<span style="color: #333399; font-weight: bold">clock_t</span> start_time <span style="color: #333333">=</span> clock();
<span style="color: #333399; font-weight: bold">clock_t</span> end_time <span style="color: #333333">=</span> sec <span style="color: #333333">*</span> <span style="color: #0000DD; font-weight: bold">1000</span> <span style="color: #333333">+</span> start_time;
<span style="color: #008800; font-weight: bold">while</span>(clock() <span style="color: #333333">!=</span> end_time);
}
<span style="color: #333399; font-weight: bold">int</span> <span style="color: #0066BB; font-weight: bold">main</span>(){
<span style="color: #333399; font-weight: bold">int</span> start_s<span style="color: #333333">=</span>clock();
<span style="color: #333399; font-weight: bold">int</span> ara[<span style="color: #0000DD; font-weight: bold">51</span>]<span style="color: #333333">=</span>{<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">12</span>,<span style="color: #0000DD; font-weight: bold">45</span>,<span style="color: #0000DD; font-weight: bold">34</span>,<span style="color: #0000DD; font-weight: bold">5</span>,<span style="color: #0000DD; font-weight: bold">6</span>,<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">12</span>,<span style="color: #0000DD; font-weight: bold">46</span>,<span style="color: #0000DD; font-weight: bold">578</span>,<span style="color: #0000DD; font-weight: bold">678</span>,<span style="color: #0000DD; font-weight: bold">68</span>,<span style="color: #0000DD; font-weight: bold">45</span>,<span style="color: #0000DD; font-weight: bold">634</span>,<span style="color: #0000DD; font-weight: bold">23</span>,<span style="color: #0000DD; font-weight: bold">2523</span>,<span style="color: #0000DD; font-weight: bold">234</span>,<span style="color: #0000DD; font-weight: bold">235</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">6</span>,<span style="color: #0000DD; font-weight: bold">57</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">6</span>,<span style="color: #0000DD; font-weight: bold">78</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">5674</span>,<span style="color: #0000DD; font-weight: bold">435</span>,<span style="color: #0000DD; font-weight: bold">234</span>,<span style="color: #0000DD; font-weight: bold">2</span>,<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">5</span>,<span style="color: #0000DD; font-weight: bold">2</span>,<span style="color: #0000DD; font-weight: bold">6342</span>,<span style="color: #0000DD; font-weight: bold">3</span>,<span style="color: #0000DD; font-weight: bold">2</span>,<span style="color: #0000DD; font-weight: bold">234</span>,<span style="color: #0000DD; font-weight: bold">14</span>,<span style="color: #0000DD; font-weight: bold">23</span>,<span style="color: #0000DD; font-weight: bold">4</span>,<span style="color: #0000DD; font-weight: bold">5</span>,<span style="color: #0000DD; font-weight: bold">234</span>,<span style="color: #0000DD; font-weight: bold">23</span>,<span style="color: #0000DD; font-weight: bold">23</span>,<span style="color: #0000DD; font-weight: bold">23455</span>,<span style="color: #0000DD; font-weight: bold">235</span>,<span style="color: #0000DD; font-weight: bold">34</span>,<span style="color: #0000DD; font-weight: bold">35</span>};
bubble_sort(ara,<span style="color: #0000DD; font-weight: bold">51</span>);
<span style="color: #008800; font-weight: bold">for</span>(<span style="color: #333399; font-weight: bold">int</span> x<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">0</span>;x<span style="color: #333333"><</span><span style="color: #0000DD; font-weight: bold">51</span>;x<span style="color: #333333">++</span>){
cout<span style="color: #333333"><<</span>ara[x]<span style="color: #333333"><<</span>endl;
}
cout<span style="color: #333333"><<</span><span style="background-color: #fff0f0">"=================TIME==================="</span><span style="color: #333333"><<</span>endl;
<span style="color: #333399; font-weight: bold">int</span> stop_s<span style="color: #333333">=</span>clock();
cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"time: "</span> <span style="color: #333333"><<</span> (stop_s<span style="color: #333333">-</span>start_s)<span style="color: #333333">/</span><span style="color: #333399; font-weight: bold">double</span>(CLOCKS_PER_SEC)<span style="color: #333333">*</span><span style="color: #0000DD; font-weight: bold">1000</span> <span style="color: #333333"><<</span> endl;
<span style="color: #008800; font-weight: bold">return</span> <span style="color: #0000DD; font-weight: bold">0</span>;
}
</pre></div>
</div>
</div>
</body>
</html>