Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. typedef struct lista
  3. {
  4.         char *wskaznik;
  5.         int numer;
  6.         struct lista *next;
  7. }
  8. listaa;
  9.  
  10. listaa *pierwszy, *active;
  11.        
  12. void funkcja(numer)
  13. {      
  14.         int i;
  15.         listaa *dodatkowy, *previous;
  16.         dodatkowy=(listaa *)malloc(sizeof(listaa));
  17.         scanf("%d", &dodatkowy->numer);
  18.         if (pierwszy==NULL)
  19.         {
  20.                 pierwszy=dodatkowy;
  21.                 active=pierwszy;
  22.                 previous=NULL;
  23.                 active->next=NULL;
  24.                 return;
  25.                
  26.         }
  27.         active=pierwszy;
  28.         previous=active;
  29.         if (dodatkowy->numer < active->numer)
  30.         {dodatkowy->next=active;
  31.         pierwszy=dodatkowy;
  32.             return;
  33.         }
  34.     while(active!=NULL)
  35.     {
  36.         if (dodatkowy->numer >= active->numer)
  37.         {
  38.             previous=active;
  39.             active=active->next;
  40.         }
  41.         else
  42.         {
  43.         if(dodatkowy->numer <= active->numer)
  44.         {
  45.             previous->next=dodatkowy;
  46.             dodatkowy->next=active;
  47.             return;
  48.         }}
  49.     }
  50.     if(active==NULL)
  51.     {
  52.         previous->next=dodatkowy;
  53.         dodatkowy->next=NULL;
  54.         return;
  55.     }
  56.    
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. int main(int argc, char **argv)
  66. { int i;
  67.     funkcja();
  68.     funkcja();
  69.     funkcja();
  70.     funkcja();
  71.     active=pierwszy;
  72.     for(i=0;i<4;i++)
  73.    
  74.     {
  75.        
  76.         printf("%d \n", active->numer);
  77.         active=active->next;
  78.        
  79.        
  80.     }
  81.    
  82.    
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement