-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort_problem.js
More file actions
40 lines (34 loc) · 882 Bytes
/
Copy pathbubble_sort_problem.js
File metadata and controls
40 lines (34 loc) · 882 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
function runProgram(input){
input = input.trim().split(/[\r\n]+/)
input.shift()
var array = input[0].split(" ").map(Number)
for(var i = 0; i < array.length-1; i++)
{
for(var j = i+1; j < array.length; j++)
{
if(array[i] > array[j])
{
var swap = array[i]
array[i] = array[j]
array[j] = swap
}
}
}
array = array.join(" ")
console.log(array)
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/,"")
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/,"")
runProgram(read);
process.exit(0);
});