-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort.src
More file actions
185 lines (174 loc) · 4.09 KB
/
Copy pathbubblesort.src
File metadata and controls
185 lines (174 loc) · 4.09 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* sort the array */
func bubbleSort(arr: integer[], size: integer) -> void
{
let n: integer;
let i: integer;
let j: integer;
let temp: integer;
n = size;
i = 0;
j = 0;
temp = 0;
while (i < n-1) {
while (j < n-i-1) {
if (arr[j] > arr[j+1])
then {
// swap temp and arr[i]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
} else ;
j = j+1;
};
i = i+1;
};
}
/* print the array */
func printArray(arr: integer[], size: integer) -> void
{
let n: integer;
let i: integer;
n = size;
i = 0;
while (i<n) {
write(arr[i]);
i = i+1;
};
}
// main funtion to test above
func main() -> void
{
let arr: integer[7];
arr[0] = 64;
arr[1] = 34;
arr[2] = 25;
arr[3] = 12;
arr[4] = 22;
arr[5] = 11;
arr[6] = 90;
printarray(arr, 7);
bubbleSort(arr, 7);
printarray(arr, 7);
}
/*
classes
--------------------------------------
|X| no class declaration
| | class declaration
| | multiple class declarations
| | no data member declaration
| | data member declaration
| | multiple data member declaration
| | no member function declaration
| | member function declaration
| | multiple member function declaration
| | no member
| | no inherited class
| | one inherited class
| | multiple inherited classes
| | private member specifier
| | public member specifier
functions: definitions
--------------------------------------
| | no main function definition
|X| main function definition
| | no free function definition
|X| free function definition
|X| multiple free function definitions
|X| no member function definition
| | member function definition
| | multiple member function definitions
|X| return type: void
| | return type: integer
| | return type: float
| | return type: id
| | return type: array (not allowed)
functions: formal parameters
--------------------------------------
|X| type: integer
| | type: float
| | type: id
|X| type: 1-dim array
| | type: n-dim array
| | type: array (with size)
|X| type: array (without size)
functions: calls
--------------------------------------
|X| free function call
| | member function call
| | parameters:0
| | parameters:1
|X| parameters:n
|X| array parameter - 1-dim
| | array parameter - n-dim
| | array parameter - with size
| | array parameter - without size
| | function call as statement
| | function call as expression factor
| | expression as parameter
variable declaration
--------------------------------------
|X| type: integer
| | type: float
| | type: string
| | type: id
|X| type: 1-dim array
| | type: n-dim array
|X| type: array (with size)
| | type: array (without size) (not allowed)
function body: local variable declarations
--------------------------------------
| | no local variable declarations
|X| local variable declarations
| | intertwined statements and variable declarations
function body: statements
--------------------------------------
| | no statement
| | 1 statement
|X| n statements
|X| if statement
|X| if: empty then or else blocks
| | if: 1-statement then or else blocks
|X| if: n-statements then or else blocks
|X| while statement
| | while: empty block
| | while: 1-statement block
|X| while: n-statement block
| | read(<variable>) statement
|X| write(<expr>) statement
|X| return(<expr>) statement
|X| assignment statement
variable + idnest
--------------------------------------
|X| id
| | id.id
| | id.id(id)
| | id(id).id
| | id(id).id()
| | id.id[id]
| | id[id].id
| | id[id].id[id]
| | id.id[id][id]
| | id[id][id].id
| | id[id][id].id[id][id]
| | id(id).id[id]
| | id(id).id[id][id]
| | expression as array index
expressions
--------------------------------------
|X| single variable
|X| involving addop
| | involving multop
|X| involving relop
| | involving addop + multop
|X| involving multop + relop
| | involving addop + multop + relop
| | involving parentheses
| | involving nested parentheses
| | involving not
| | involving sign
|X| involving literals
| | involving variable + idnest
|X| involving function calls
| | involving all the above in one expression
*/