Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct osoba
  5. {
  6. int wiek;
  7. struct osoba *next;
  8. };
  9.  
  10. struct osoba *head;
  11. struct osoba *last;
  12. struct osoba *pom;
  13.  
  14. int main()
  15. {
  16.  
  17. printf("------------------------------------------\n");
  18. printf("Wyjscie z programu: 0\n");
  19. printf("Tworzenie listy: 1\n");
  20. printf("Dodawanie elementu na poczatek listy: 2\n");
  21. printf("Dodawanie elementu na koniec listy: 3\n");
  22. printf("Dodawanie elementu po zadanym listy: 4\n");
  23. printf("Usuwanie elementu wybranego listy: 5\n");
  24. printf("------------------------------------------\n");
  25.  
  26. int choice,x;
  27. scanf("%d",&choice);
  28. while(choice!=0)
  29. {
  30. if(choice==0)
  31. {
  32. break;
  33. }
  34. else if(choice==1)
  35. {
  36. create();
  37. }
  38. else if(choice==2)
  39. {
  40. printf("Podaj wiek: ");
  41. scanf(" %d",&x);
  42. dodajElement(x);
  43. }
  44.  
  45. }
  46.  
  47.  
  48. return 0;
  49. }
  50.  
  51. void create()
  52. {
  53. head=NULL;
  54. last=NULL;
  55. }
  56.  
  57. void dodajElement(int x)
  58. {
  59. pom=(struct osoba*)malloc(sizeof(struct osoba));
  60. head=pom;
  61. pom->next=NULL;
  62. pom->wiek=x;
  63. printf("%d\n",pom->wiek);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement