#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct item {
    item *next;
    int data;
};
void print_list(const item *first)
{
    for (const item *cur = first; cur; cur = cur->next) {
        printf("%d ", cur->data);
    }
    puts("");
}
void sort_list(item **first){
    item *cur, *prev, *next;
    bool flag;
    if (*first)
    {
        flag = true;
        cur = *first;
        while (flag)
        {
            flag = false;
            prev = NULL;
            cur  = *first;
            next = cur->next;
            while (next)
            {  	if (next->data < cur->data)
                  {
                    flag = true;
                    cur->next = next->next;
                    next->next = cur;
                    cur = next;
                if (prev) prev->next = cur;
                    else *first = cur;
                  }
                prev = cur;
                cur  = cur->next;
                next = cur->next;
             }
         }
     }
}

int main()
{	char str[0xF];
    item *first, *cur, *tmp;
    first = NULL;
    puts("Input integer value or ENTER");
    while (gets(str), strlen(str)!=0) {
        cur = new item;
        cur->data = atoi(str);
        cur->next = first;
        first = cur;
    }
    puts("\nInputed spisok integer value");
    print_list(first);
    puts("\nSorted spisok integer value");	sort_list(&first);
    print_list(first);
    cur = first;
    while (cur) {
        tmp = cur;
        cur = cur->next;
        delete tmp;
    }
    getch();
first=tmp=NULL;
    return 0;
}

