Advertisement
Duoshot

Untitled

Oct 24th, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #define SIZE 40
  2.  
  3. int main()
  4. {
  5. int v[SIZE];
  6. int i, j, tmp;
  7.  
  8. /* Initialize array to random positive integers, mod 256 */
  9. for (i = 0; i < SIZE; i++) {
  10. v[i] = rand() & 0xFF;
  11. printf(“v[%-d]: %d\n”, i, v[i]);
  12. }
  13.  
  14. /* Sort the array using an insertion sort */
  15. for (i = 1; i < SIZE; i++) {
  16. tmp = v[i];
  17. for (j = i; j > 0 && tmp < v[j-1]; j--)
  18. v[j] = v[j-1];
  19. v[j] = tmp;
  20. }
  21.  
  22. /* Print out the sorted array */
  23. printf(“\nSorted array:\n”);
  24. for (i = 0; i < SIZE; i++)
  25. printf(“v[%-d]: %d\n”, i, v[i]);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement