Array Sorting algorithm (Ascending Values)

Program Program Source #include <stdio.h> void sort(int array[],int size) { int temp,i,j; int tempsize=size-1; for(i=0;i<tempsize;i++) { for(j=0;j<tempsize;j++) { if(array[j]>array[j+1]) { temp=array[j+1]; array[j+1]=array[j]; array[j]=temp; } } } } int main() { int number[4]={40,30,10,20}; sort(number,4); int i; for(i=0;i<4;i++) { printf(“%d\n”,number[i]); } return 0; }

Array Sorting algorithm (Descending Values)

Program Program Source #include <stdio.h> void sort(int array[],int size) { int temp,i,j; int tempsize=size-1; for(i=0;i<tempsize;i++) { for(j=0;j<tempsize;j++) { if(array[j]<array[j+1]) { temp=array[j+1]; array[j+1]=array[j]; array[j]=temp; } } } } int main() { int number[4]={40,30,10,20}; sort(number,4); int i; for(i=0;i<4;i++) { printf(“%d\n”,number[i]); } return 0; }

Simple Stack Implementation with array

Program Program Source #include <stdio.h> int stackarray[10]; int top=-1; void push(int value) { top++; if(top<10) { stackarray[top]=value; } else{ top–; printf(“Stack Overflow\n”); } } int pop() { if(top==-1) { printf(“Stack underflow\n”); return 0; } else return stackarray[top–]; } int main() { push(10); push(20); push(30); push(40); printf(“%d\n”,pop()); printf(“%d\n”,pop()); printf(“%d\n”,pop()); printf(“%d\n”,pop()); return 0; }