Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 7
- void sortInt();
- int main(void) {
- int numbers[SIZE] = {10, 7, -5, 6, 1, 8, 11};
- printf("Before: ");
- int i = 0;
- int* n = numbers;
- while (i++ < SIZE)
- printf("%d, ", *n++);
- sortInt(numbers, SIZE);
- printf("\nAfter: ");
- n = numbers;
- i = 0;
- while (i++ < SIZE)
- printf("%d, ", *n++);
- }
- void sortInt(int *numbers, int length) {
- int top = 0;
- int temp = 0;
- while (top < length) {
- while (top > 0 && *numbers < *(numbers - 1)) {
- temp = *numbers;
- *numbers = *(numbers - 1);
- *(numbers - 1) = temp;
- top--;
- numbers--;
- }
- top++;
- numbers++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement