#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
struct Element
{
struct Element *next;
char *u;
};
struct Element* InitSingleLinkedList()
{
struct Element *list;
list = (struct Element*)malloc(sizeof(struct Element));
list->next=NULL;
list->u=malloc(100*sizeof(char));;
memset(list->u,'\0' , 100*sizeof(char));
return list;
}
struct Element *bsort(struct Element *list)
{
int SwapsInIteration=1;
struct Element *last;
char*swap;
while(SwapsInIteration>0)
{
SwapsInIteration=0;
for(last=list->next;last->next!=NULL;last=last->next)
{
if(strlen(last->u)>(strlen(last->next->u)))
{
swap=last->u;
last->u=last->next->u;
last->next->u=swap;
SwapsInIteration+=1;
}
}
}
return list;
}
int main (int argc, char const *argv[])
{
unsigned long int i=0,len,inword=0,j=0;
char str[100];
struct Element *new;
struct Element *last;
struct Element *list;
list=InitSingleLinkedList();
gets(str);
len=strlen(str);
last=list;
if (len>0 && !isspace(str[0]))
{
inword=1;
}
for (i=0;i<len;i++)
{
if(inword==1)
{
new = InitSingleLinkedList();
while (i<len && (!isspace(str[i])))
{
new->u[j]=str[i];
i++;
j++;
}
inword=0;
last->next=new;
last=new;
}
if(inword==0 && (!isspace(str[i])))
{
inword=1;
j=0;
if(i>0) i--;
}
}
bsort(list);
for (last=list->next;last->next!=NULL;last=new)
{
new=last->next;
printf("%s ",last->u);
}
printf("%s\n",last->u);
for (last=list;last!=NULL;)
{
new=last->next;
free(last->u);
free(last);
last=new;
list=last;
}
return 0;
}