All pastes #503374 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-22 21:10 UTC
rendered paste body
#include <stdio.h>

typedef char Dane;
struct lista_dwa
{
       Dane d;
       struct lista_dwa *nast,*pop;
};
typedef struct lista_dwa Element2;
typedef Element2 *Lista2;
       
Lista2 napis_na_liste(char *s)
{
       Lista2 el,pocz=NULL,lst;
       if(*s)
       {
             pocz=malloc(sizeof(Element2));
             pocz->d=*s;
             pocz->nast=NULL;
             pocz->pop=NULL;    
             lst=pocz;
             while(*++s)
             {
                lst->nast=malloc(sizeof(Element2));
                lst->nast->pop=lst;
                lst=lst->nast;
                lst->d=*s;
                lst->nast=NULL;
             }
       }       
       return pocz;
}       
void zamien(Lista2 el1, Lista2 el2)
{
    char c;
    c=el1->d;
    el1->d=el2->d;
    el2->d=c;
}
int il_el(Lista2 lst)
{
    Lista2 tmp;
    int i;
    tmp=lst;
    if(!tmp) return 0;
    for(i=0;tmp->nast;i++,tmp=tmp->nast);
    return ++i;
}
Lista2 sort(Lista2 lst)
{
       Lista2 tmp;
       int k,i=il_el(lst);    
       for(k=0;k<i;k++)
       {
           tmp=lst;
           while(tmp->nast)
           {
           if((tmp->d)>(tmp->nast->d)) zamien(tmp->nast,tmp);
           tmp=tmp->nast;
           }
       }
       return lst;
}
main()
{
char napis[100]="siemxfgjzbmdgzdkah";
Lista2 lst2,e1,e2;
lst2=napis_na_liste(napis); 

printf("%d\n",il_el(lst2));
lst2=sort(lst2);
printf("%d\n",il_el(lst2));

do
{
     printf("%c",lst2->d);
     lst2=lst2->nast;                                    
}
while(lst2);

getch();
}