Last change
on this file since 185 was
165,
checked in by mulligan, 10 years ago
|
Some example C programs that the emulator can run.
|
File size:
552 bytes
|
Line | |
---|
1 | #include "stdio.h" |
---|
2 | |
---|
3 | void swap(int *a, int *b) |
---|
4 | { |
---|
5 | int t=*a; *a=*b; *b=t; |
---|
6 | } |
---|
7 | void sort(int arr[], int beg, int end) |
---|
8 | { |
---|
9 | if (end > beg + 1) |
---|
10 | { |
---|
11 | int piv = arr[beg], l = beg + 1, r = end; |
---|
12 | while (l < r) |
---|
13 | { |
---|
14 | if (arr[l] <= piv) |
---|
15 | l++; |
---|
16 | else |
---|
17 | swap(&arr[l], &arr[--r]); |
---|
18 | } |
---|
19 | swap(&arr[--l], &arr[beg]); |
---|
20 | sort(arr, beg, l); |
---|
21 | sort(arr, r, end); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | int main() |
---|
26 | { |
---|
27 | int array[3] = { 3, 2, 1 }; |
---|
28 | sort(array, 0, 2); |
---|
29 | if(array[0] == 1) |
---|
30 | printf("Yes"); |
---|
31 | else |
---|
32 | printf("No"); // Surprise: no should be printed! |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
Note: See
TracBrowser
for help on using the repository browser.