Advertisement
Guest User

Parcare

a guest
Mar 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct elem {
  5.     char licensePlate[36];
  6.     struct elem *urm;
  7. }node;
  8.  
  9. node *root = NULL;
  10. node *ultim = NULL;
  11.  
  12. node *create(char valoare[36]) {
  13.     node *p;
  14.     p = (node*)malloc(sizeof(node));
  15.     strcpy(p->licensePlate, valoare);
  16.     p->urm = NULL;
  17.     return p;
  18. }
  19.  
  20. node *add(node *nou) {
  21.     nou->urm = root;
  22.     root = nou;
  23.     return root;
  24. }
  25.  
  26. node *enterTheParking(char licensePlate[36]) {
  27.     node *nou = create(licensePlate);
  28.     if (root == NULL)
  29.     {
  30.         ultim = nou;
  31.     }
  32.     root = add(nou);
  33. }
  34.  
  35.  
  36. node *exitTheParking() {
  37.     node *aux;
  38.     if (root == NULL) {
  39.         printf("The parking lot is empty!");
  40.         return NULL;
  41.     }
  42.     else
  43.     {
  44.         aux = root;
  45.     }
  46.     root = root->urm;
  47.     free(aux);
  48. }
  49.  
  50.  
  51. void showCars() {
  52.     node *p;
  53.     for (p = root; p!= NULL; p = p->urm) {
  54.         printf("%s\n", p->licensePlate);
  55.     }
  56. }
  57.  
  58. int main()
  59. {
  60.  
  61.     enterTheParking("BH14CAP");
  62.     enterTheParking("BH10BXD");
  63.     enterTheParking("HD09LBO");
  64.     showCars();
  65.     exitTheParking();
  66.     showCars();
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement