Skip to content

Instantly share code, notes, and snippets.

@paxswill
Created November 4, 2011 06:41
Show Gist options
  • Save paxswill/1338797 to your computer and use it in GitHub Desktop.
Save paxswill/1338797 to your computer and use it in GitHub Desktop.
Tiny BubbleSort
/*
This breaks a number of rules, and probably won't work with systems with non-32bit ints
Minimal form (180 chars):
main(){int n,*s,i=0,j,t;scanf("%d",&n);s=malloc(n);while(i<n)scanf("%d",s+i++);while(--i)for(j=0;j<i;)if(s[j]>s[++j]){t=s[--j];s[j]=s[++j];s[j]=t;}while(i<n)printf("%d ",s[i++]);}
Standard(ish) form:
*/
main(){
int n,*s,i=0,j,t;
scanf("%d",&n);
s=malloc(n);
while(i<n)
scanf("%d",s+i++);
while(--i)
for(j=0;j<i;)
if(s[j]>s[++j]){
t=s[--j];
s[j]=s[++j];
s[j]=t;
}
while(i<n)
printf("%d ",s[i++]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment