This is a draft cheat sheet. It is a work in progress and is not finished yet.
Random Range
rand() % 4 = 0~3
rand() % 11+1 = 1~11 |
Bubble Sort
7 23 5 78 22
5 7 23 22 78
5 7 22 23 78
5 7 22 23 78
if (list[walker] < list[walker - 1]) {
temp = list[walker]; / exchange elements /
list[walker] = list[walker - 1];
list[walker - 1] = temp; } |
Initialize 4x5 Array
for(i = 0; i < 4; i ++) { table[i][0] = i * 20;
for(j = 1; j < 5; j ++) { table[i][j] = table[i][j - 1] + 1; }; }; |
Function Stack
int Foo (int a, int b) { int x; int y = 10;
x = ay+b; return x;} |
|
|
Recursive to Iteration
long factorial(int n) { if (n == 0) {
return 1; }
else { return (n * factorial (n-1)); }; }
long factorial (int n) { int i; long fact;
if (n == 0) return 1; else {
for (i = 1, fact = 1; i <= n; i ++) {
fact = fact * i; } return fact; } } |
Copy Text
int main(void) {
FILE +fp1, +fp2; int c;
if (!(fp1 = fopen(“aaa.dat”, “r”))) {
printf(“could not open file for reading. \n”); exit; }
if (!(fp2 = fopen(“bbb.dat”, “w”))) {
printf(“could not open file for writing. \n”); exit;}
while ((c = fgetc(fp1)) != EOF) { fputc(c, fp2); }
fclose(fp1); fclose(fp2); return 0; } |
Insertion Sort
7 23 5 78 22
7 23 5 78 22
5 7 23 78 22
5 7 23 78 22
if (temp < list[walker]) { list[walker + 1] = list[walker]; walker --; }
else { located = TRUE; }; |
|