Ну-с, проблемы с реализацией. Ниже будет приаттачен мой индусский быдлокод. Вопросов 2. Первый - правильно ли сортируется? Второй - как реализовать печать?
Код
#include <stdio.h>
#include <stdlib.h>
int main () {
int a;
struct list {int data; struct list *next;};
struct list *h, *t, *p,*r,*c=NULL,*d;
h=(struct list*)malloc(sizeof(struct list));
h->data=0;
h->next=NULL;
while (scanf("%d", &a)==1){
p=(struct list*)malloc(sizeof(struct list));
p->data=a;
p->next=NULL;
if(h->data==0){
h->data=p->data;
continue;
}
if(p->data<h->data){
p->next=h;
h=p;
}
if(p->data>h->data){
for(t=h;t->next!=NULL;t=t->next){
if(p->data<t->next->data){
c=t->next;
t->next=p;
p->next=c;
}
}
t->next=p;
}
}
return 0;
}
#include <stdlib.h>
int main () {
int a;
struct list {int data; struct list *next;};
struct list *h, *t, *p,*r,*c=NULL,*d;
h=(struct list*)malloc(sizeof(struct list));
h->data=0;
h->next=NULL;
while (scanf("%d", &a)==1){
p=(struct list*)malloc(sizeof(struct list));
p->data=a;
p->next=NULL;
if(h->data==0){
h->data=p->data;
continue;
}
if(p->data<h->data){
p->next=h;
h=p;
}
if(p->data>h->data){
for(t=h;t->next!=NULL;t=t->next){
if(p->data<t->next->data){
c=t->next;
t->next=p;
p->next=c;
}
}
t->next=p;
}
}
return 0;
}