Advertisement
Patresss

Untitled

Jun 24th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct tnode {
  2. int value;
  3. struct tnode * next;
  4. };
  5.  
  6. void wypisz(struct tnode *head) {
  7.     struct tnode *wsk=head;
  8.     while (wsk!=NULL){
  9.         printf("%d \n", wsk->value);
  10.         wsk=wsk->next;}}
  11.  
  12. void uwolnij(struct tnode **head){
  13.     struct tnode *wsk=*head;
  14.     struct tnode *wsk2;
  15.     while (wsk!=NULL){
  16.         wsk2=wsk->next;
  17.         free(wsk);
  18.         wsk=wsk2;
  19.         //printf("TEST %d \n", (*head)->value);}}
  20.  
  21. struct tnode *d_na_p (struct tnode *head,int war){
  22.     struct tnode *new=malloc(sizeof(struct tnode));
  23. if (new==NULL)
  24. {   printf("Blad\n");
  25.     return NULL;}
  26.  
  27.     new->value=war;
  28.     new->next=head;
  29.     return new;}
  30.  
  31. struct tnode * d_na_k(struct tnode *head, int war)
  32. {struct tnode *new=(struct tnode*)malloc(sizeof(struct tnode));
  33. if (new==NULL)
  34. {printf("Blad\n");
  35. return NULL;}
  36. new->value=war;
  37. new->next=NULL;
  38. if (head==NULL)
  39.     head=new;
  40. else
  41. {struct tnode *w = head;
  42. while(w->next != NULL)
  43.     {w=w->next;  }
  44.     w->next=new;
  45. return head;}}
  46.  
  47. struct tnode * d_do_p(struct tnode *head, int war){
  48. struct tnode *new=(struct tnode*)malloc(sizeof(struct tnode));
  49. if (new==NULL){
  50.     printf("Blad\n");
  51.     return NULL;}
  52. new->value=war;
  53. new->next=NULL;
  54. if (head==NULL)
  55.     head=new;
  56. else{
  57.     struct tnode *w=head;
  58.     if ((*head).value >= (*new).value){
  59.         new->next=head;
  60.         head=new;}
  61.     else{
  62.         while ((*w).next != NULL){
  63.         if (((*w).value <= (*new).value)&&((*w).next->value >= (*new).value))
  64.             {
  65.                 (*new).next=(*w).next;
  66.                 (*w).next=new;
  67.                 break;
  68.             }
  69.             w=(*w).next;
  70.         }
  71.         if ((*w).next == NULL)
  72.             (*w).next=new;}}
  73. return head;}
  74.  
  75. struct tnode * szukaj_liczby(struct tnode *head, int war)
  76. {
  77. struct tnode *w=head; //w miejsce
  78. if (head==NULL)
  79. {printf("Blad\n");
  80. return NULL;}
  81. else{  
  82.     while(w->value!=war && w->next!=NULL){
  83.     w=w->next;}
  84.     if(w->value ==war)
  85. puts("[szukaj] Znalazlo liczbe");
  86. else puts("[szukaj] Nie znalazlo liczby");}}
  87.  
  88. struct tnode * usun_liczbe(struct tnode *head, int war){
  89.     int n=0;
  90. struct tnode *wskaz=head;
  91. struct tnode *w=head;
  92.  
  93. if (head==NULL){
  94.     printf("Blad\n");
  95.     return NULL;}
  96. else{
  97.     while(w->value!=war && w->next!=NULL){
  98.         wskaz=w;
  99.     w=w->next;
  100.     n++;}
  101.  
  102. if(w->value!= war)
  103. puts("[usuwanie] Nie znalazlo liczby");
  104. else{
  105.         if(n==0)
  106.         head=w->next;
  107.         wskaz->next=w->next;}}
  108. return head;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement