Facebook
From Soiled Terrapin, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 295
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct list{
  4. int d;
  5. struct list *next;
  6. } list;
  7. list *head;
  8.  
  9. void wypisz(){
  10.     list* pom=head;
  11. while(pom!=NULL){
  12.     printf("%i\n",pom->d);
  13.     pom=pom->next;}
  14. }
  15.  
  16. void usun(int x){
  17. int i=0;
  18. list* pom=head;
  19. for(i;i<x-1;i++)
  20. {
  21.      pom=pom->next;
  22. }
  23. list* wsk=pom->next;
  24.   pom->next=wsk->next;
  25.   free(wsk);
  26. }
  27.  
  28. int main()
  29. {
  30.      int i,x;
  31.      for(i=0;i<4;i++)
  32.      {
  33.          list* nowy=(list*)malloc(sizeof(list));
  34.          nowy->d=i;
  35.          if(i==0){nowy->next=NULL;}else {nowy->next=head;}
  36.             head=nowy;
  37.      }
  38.      wypisz();
  39.      printf("ktory chcesz usunac ");
  40.      scanf("%i",&x);
  41.      usun(x-1);
  42.      wypisz();
  43.     return 0;
  44. }
  45.  
  46.