/* autor: Krzysztof 'frimer' Zmijewski 
 * 
 * prog: " insercik.c " - Program sortuje liczby metoda insert sort
 *
 * Kompilator: gcc 4.3.3
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */


#include <stdio.h>
#include <stdlib.h>

#define MAX 5		/* rozmiar tablicy */
 
int main (void) {
int i, j, tmp, tab[MAX];

system("clear");		/* czyscimy ekran */

/* wprowadzamy dane */
	for (i=0; i < MAX; i++) {	
		printf("Podaj liczbe %d z %d = ", i+1, MAX);
			scanf("%d", &tab[i]);  
	}

/* wyswietlamy dane przed posortowaniem */
	printf("\nPrzed posortowaniem: ");
		for(i = 0; i < MAX; i++)
	printf("%d ",tab[i]);

/* sortujemy dane */
	for(i=1; i<MAX; i++) {
		tmp = tab[i];
		j = i-1;
		while (tmp < tab[j] && j>=0) {
			tab[j+1] = tab[j];
			j = j-1;
		}
		tab[j+1] = tmp;
	}

/* wyswietlamy dane po posortowaniu */
	printf("\n\nPo sortowaniu: ");
		for(i=0; i<MAX; i++)
	printf("%d ", tab[i]);
    puts("\n");

return 0;
}

