Xv6 with picoc & Linkage editor
v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
|
00001 #include <stdio.h> 00002 00003 int array[16]; 00004 00005 //Swap integer values by array indexes 00006 void swap(int a, int b) 00007 { 00008 int tmp = array[a]; 00009 array[a] = array[b]; 00010 array[b] = tmp; 00011 } 00012 00013 //Partition the array into two halves and return the 00014 //index about which the array is partitioned 00015 int partition(int left, int right) 00016 { 00017 int pivotIndex = left; 00018 int pivotValue = array[pivotIndex]; 00019 int index = left; 00020 int i; 00021 00022 swap(pivotIndex, right); 00023 for(i = left; i < right; i++) 00024 { 00025 if(array[i] < pivotValue) 00026 { 00027 swap(i, index); 00028 index += 1; 00029 } 00030 } 00031 swap(right, index); 00032 00033 return index; 00034 } 00035 00036 //Quicksort the array 00037 void quicksort(int left, int right) 00038 { 00039 if(left >= right) 00040 return; 00041 00042 int index = partition(left, right); 00043 quicksort(left, index - 1); 00044 quicksort(index + 1, right); 00045 } 00046 00047 void main() 00048 { 00049 int i; 00050 00051 array[0] = 62; 00052 array[1] = 83; 00053 array[2] = 4; 00054 array[3] = 89; 00055 array[4] = 36; 00056 array[5] = 21; 00057 array[6] = 74; 00058 array[7] = 37; 00059 array[8] = 65; 00060 array[9] = 33; 00061 array[10] = 96; 00062 array[11] = 38; 00063 array[12] = 53; 00064 array[13] = 16; 00065 array[14] = 74; 00066 array[15] = 55; 00067 00068 for (i = 0; i < 16; i++) 00069 printf("%d ", array[i]); 00070 00071 printf("\n"); 00072 00073 quicksort(0, 15); 00074 00075 for (i = 0; i < 16; i++) 00076 printf("%d ", array[i]); 00077 00078 printf("\n"); 00079 } 00080