C

C

C Q: Write the code to sort an array of integers. A: /* BEGIN C SNIPET */ void bubblesort (int x[ ], int lim) { int i, j, temp; for (i = 0; i < lim; i+) { for (j = 0; j < lim-1-i; j+) { if (x[j] > x[j+1]) { temp = x[j]; x[j] = x[j+1]; x[j+1] = temp; } /* end if */ } /* end for j */ } /* end for i */ } /* end bubblesort */ /* END C SNIPET */ Some optimizations that can be made are that a single-element array does not need to be sorted; therefore, the "for i" loop only needs to go from 0 to lim… More information...

User: Saurabh Dayal
Page: vlsiquestions.webnode.com (?)

Build your Free Website!

  • 100% free
  • In only 5 min
  • Your own domain
  • No Ads
  • No installation
  • No technical skills
Create website for free

Follow us on Facebook!

Webnode on Facebook

Webnode on Twitter:

Hudba pro váš web zdarma? Víme, kde ji najdete! http://t.co/bfQMA7O3

Follow us!
Forgot your password?