Advertisement
andidegn

Untitled

Jan 8th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void sortInt();
  4.  
  5. int main(void) {
  6.     signed int numbers[5] = {10, 7, -5, 6, 1}; 
  7.    
  8.     printf("Before: ");
  9.     int i;
  10.     int* n = numbers;
  11.     for (i = 0; i < 5; i++)
  12.         printf("%d, ", *n++);
  13.     sortInt(numbers);
  14.     printf("\nAfter: ");
  15.     n = numbers;
  16.     for (i = 0; i < 5; i++)
  17.         printf("%d, ", *n++);
  18. }
  19.  
  20. void sortInt(signed int *numbers) {
  21.     int top = 0;
  22.     int temp = 0;
  23.     while (top <= sizeof(numbers)) {
  24.         while (top > 0 && *numbers < *(numbers - 1)) {
  25.             temp = *numbers;
  26.             *numbers = *(numbers - 1);
  27.             *(numbers - 1) = temp;
  28.             top--;
  29.             numbers--;
  30.         }
  31.         top++;
  32.         numbers++;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement