Skip to content

Instantly share code, notes, and snippets.

@Esarve
Created June 6, 2017 17:59
Show Gist options
  • Save Esarve/c3b3ed17b6b057ed9b90c5faa4dbf96c to your computer and use it in GitHub Desktop.
Save Esarve/c3b3ed17b6b057ed9b90c5faa4dbf96c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int display(int store[], int i);
int main()
{
int x,i,n,k,temp,flag;
i=1;
int store[20];
for (n=0;n<20;n++){
printf("Input: ");
scanf("%d",&x);
if (n!=0 && store[n-1]>x) {
k=n;
while(n!=0 && store[n-1]>x){
temp = store[n-1];
store[n-1]=x;
store[n]=temp;
n--;
}
n=k;
printf("Current N is: %d \n",n);
display(store, i);
i++;
}else{
printf("Ding!");
printf("Current N is: %d \n",n);
store[n]=x;
display(store, i);
i++;
}
}
}
int display(int store[], int i){
int j=0;
printf("\nCurrent Sort: ");
while(j<i){
printf("%d ",store[j]);
j++;
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment