fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct elem
  4. {
  5. char value[5];
  6. struct elem *prev, *next;
  7. } elem;
  8.  
  9.  
  10. void wstaw(char *tab, elem **head, elem **tail){
  11. elem *tmp; /*wskaznik na nowy element*/
  12. tmp=(void *)malloc(sizeof(elem));
  13. tmp->prev = NULL;
  14. tmp->next = (*head);
  15. int i;
  16. for(i=0; i<5; i++)
  17. tmp->value[i]=tab[i]; /*przypisanie wartosci dla tmp*/
  18. if(!(*head)) /*sprawdzenie czy kolejka byla pusta*/
  19. {
  20. (*head) = tmp; /*przepiecie glowy i ogona na jedyny element*/
  21. (*tail) = tmp;
  22. }
  23. else{
  24. (*head)->prev=tmp; /*element poprzedni wskazuje na ostatni POPRZEDNI KOLEJNEGO WSKAZUJE NA NOWA WARTOSC */
  25. (*head) = tmp; /*przepiecie glowy na element ostatni, */
  26. }
  27. }
  28.  
  29.  
  30. int usun(elem **head, elem **tail){
  31. if(!(*tail)) /*sprawdza czy kolejka nie jest pusta*/
  32. {
  33. printf("lista pusta");
  34. return ;
  35. }
  36. else /*jak nie jest to zdejmuje element*/
  37. {
  38. int x;
  39. elem *tmp;
  40. tmp = (*tail); /* przypisanie tmpowi wartosci tail*/
  41. (*tail) = tmp->prev; /* przepiecie tail na element wczesniejszy*/
  42. if((*tail)) /*sprawdza czy po przepieciu tail wskazuje na nulla*/
  43. {
  44. (*tail)->next = NULL; /*przepiecie tail->next na null*/
  45. }
  46. x=tmp->value; /*zwrocenie wartosci temu tam po usunieciu*/
  47. free(tmp);
  48. return x;
  49. }
  50. }
  51.  
  52.  
  53. int kasuj(elem **tail, elem **head){
  54. elem *tmp; /*wskaznik na nowy element*/
  55. *tail=NULL;
  56. *head=NULL;
  57. printf("\nUsuwam:");
  58. if(*tail){
  59. int x;
  60. elem *tmp;
  61. tmp = (*tail); /* przypisanie tmpowi wartosci tail*/
  62. (*tail) = tmp->prev; /* przepiecie tail na element wczesniejszy*/
  63. if((*tail)) /*sprawdza czy po przepieciu tail wskazuje na nulla*/
  64. {
  65. (*tail)->next = NULL; /*przepiecie tail->next na null*/
  66. }
  67. x=tmp->value; /*zwrocenie wartosci temu tam po usunieciu*/
  68. free(tmp);
  69. }
  70.  
  71. }
  72.  
  73. elem szukaj(elem *tail, char *tab){
  74. if(!tail)
  75. {
  76. printf("kolejka pusta");
  77. }
  78. else /*jesli nie jest pusta*/
  79. {
  80. while(tail) /*przechodzimy petla dopoki tail nie wskazuje na null*/
  81. {
  82. if(strcmp(tail->value, tab)==0){
  83. return *tail;
  84. }
  85. tail = tail->prev; /*przepinamy tail na wczesniejsz element w klejce*/
  86. }
  87. return nullptr;
  88. }
  89. }
  90.  
  91. /* int licz1=1;
  92.   int licz2=1;
  93.   int licz1_1=1;
  94.   int licz2_1=1;
  95.   int tmp1;
  96.   int tmp2;
  97. */
  98.  
  99.  
  100. void wypisz(elem *tail)
  101. {
  102. if(!tail)
  103. {
  104. printf("kolejka pusta");
  105. }
  106. else /*jesli nie jest pusta*/
  107. {
  108. while(tail) /*przechodzimy petla dopoki tail nie wskazuje na null*/
  109. {
  110. printf("%s / ",tail->value); /*wypisujemy element*/
  111. tail = tail->prev; /*przepinamy tail na wczesniejsz element w klejce*/
  112. }
  113. printf("");
  114. }
  115. }
  116.  
  117. int main()
  118. {
  119. elem *head=NULL;
  120. elem *tail=NULL;
  121.  
  122. char slowo1[5] = "ala";
  123. char slowo2[5] = "ma";
  124. char slowo3[5] = "kota";
  125. char slowo4[5] = "kota";
  126.  
  127. wstaw(slowo1,&head, &tail);
  128. wstaw(slowo2,&head, &tail);
  129. wstaw(slowo3,&head, &tail);
  130. wstaw(slowo4,&head, &tail);
  131.  
  132. printf("Wypisuje liste:\n");
  133. wypisz(tail);
  134. printf("\n");
  135.  
  136. printf("Szukam slowa 'ma' \n");
  137. szukaj(tail, slowo2);
  138.  
  139.  
  140.  
  141.  
  142. printf("\n");
  143. /*printf("wywalilem : %d",usun(&head,&tail));
  144.  
  145. printf("\nDodaje 11 i 34 do listy");
  146. wstaw(11,&head, &tail);
  147. wstaw(34,&head, &tail);
  148. printf("\n");
  149. wypisz(tail);
  150. printf("\n\n");
  151. printf("Podaj zmienna do poszukania: \n");
  152. scanf("%d", &zk);
  153. printf("\n");
  154. szukaj(tail, zk);
  155. printf("\n");
  156. wypisz(tail);
  157. kasuj(&tail, &head);
  158. printf("\n");
  159. printf("Wypisuje liste:\n");
  160. wypisz(tail);*/
  161. return 0;
  162. }
  163.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'usun':
prog.c:34:5: warning: 'return' with no value, in function returning non-void
     return ;
     ^
prog.c:46:2: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
 x=tmp->value; /*zwrocenie wartosci temu tam po usunieciu*/
  ^
prog.c: In function 'kasuj':
prog.c:67:2: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
 x=tmp->value; /*zwrocenie wartosci temu tam po usunieciu*/
  ^
prog.c:59:9: warning: variable 'x' set but not used [-Wunused-but-set-variable]
     int x;
         ^
prog.c:54:7: warning: unused variable 'tmp' [-Wunused-variable]
 elem *tmp; /*wskaznik na nowy element*/
       ^
prog.c: In function 'szukaj':
prog.c:82:16: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
             if(strcmp(tail->value, tab)==0){
                ^
prog.c:87:16: error: 'nullptr' undeclared (first use in this function)
         return nullptr;
                ^
prog.c:87:16: note: each undeclared identifier is reported only once for each function it appears in
prog.c: In function 'wypisz':
prog.c:113:16: warning: zero-length gnu_printf format string [-Wformat-zero-length]
         printf("");
                ^
prog.c: In function 'kasuj':
prog.c:71:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function 'szukaj':
prog.c:89:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty