// http://www.programmingsimplified.com/c/source-code/c-program-bubble-sort
// https://en.wikipedia.org/wiki/Bubble_sort
/* Bubble sort code */
#include <stdio.h>

#define MIDA	100

void main() {
	int v[MIDA], n, i, j, k, aux;

	printf("Numero de elementos\n"); // 4
	scanf("%d", &n);
	printf("Intro %d enteros\n", n); // 3 4 2 1
	for (i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	printf("\n");

	for (i=0;i < (n-1);i++) {
		for (j=0;j < n-i-1;j++) {
			if (v[j] > v[j+1]) {
				aux	= v[j];
				v[j]	= v[j+1];
				v[j+1]	= aux;
			}
			for (k=0;k<n;k++) printf("%d ", v[k]); printf("\n");
		}
		printf("%d ultimos elementos ordenados.\n\n", i+1);
	}

	printf("Y por tanto todos ordenados:\n");
	for (k=0;k<n; k++) printf("%d ", v[k]); printf("\n");
}

/*
$ ./a.out
Numero de elementos
4
Intro 4 enteros
3 4 2 1

3 4 2 1 
3 2 4 1 
3 2 1 4 
1 ultimos elementos ordenados.

2 3 1 4 
2 1 3 4 
2 ultimos elementos ordenados.

1 2 3 4 
3 ultimos elementos ordenados.

Y por tanto todos ordenados:
1 2 3 4 
$
*/

