bubble sort

 avatar
user_3763047219
c_cpp
2 years ago
561 B
3
Indexable
Never
#define _CRT_SCURE_NO_WARNINGS
#include <iostream>

void bubble_sort(int data[]);

void bubble_sort(int data[]) {
	for (int i = 4; i >= 0; i--) {
		for (int j = 4; j > 0; j--) {
			if (data[j] < data[j - 1]) {
				int temp;
				temp = data[j];
				data[j] = data[j - 1];
				data[j - 1] = temp;
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		printf("%d ", data[i]);
	}
	printf("%d", data[4]);
}

#include <stdio.h>

int main() {
	int data[5];
	for (int i = 0; i < 5; i++)
		scanf("%d", &data[i]);
	bubble_sort(data);

	return 0;
}