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

void swap(int *a, int *b){
	int c = *a;
	*a = *b;
	*b = c;
}

void print_list(struct list *l) {
	for(;l;l = l->next)
		printf("%d\n", l->value);
}

void push_list(struct list **l, int val) {
	struct list *prvek = malloc(sizeof(struct list));
	prvek->value = val;
	prvek->next = *l;
	*l = prvek;
}

void pop_list(struct list **l){
    struct list *to_remove = *l;
    *l = (*l)->next;
    free(to_remove);
}

void create_new_list(struct list **l){
	*l = NULL;
}

void erase_list(struct list **l) {
	while (*l) pop_list(l);
}

void buble_sort(struct list *l){
	struct list *i, *j;
	for (i=l;i;i=i->next)
		for (j=l;j;j=j->next)
			if (j->next && j->value > j->next->value)
				swap(&j->value,&j->next->value);
}


