Created
November 4, 2011 06:41
-
-
Save paxswill/1338797 to your computer and use it in GitHub Desktop.
Tiny BubbleSort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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