Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct li
  5. {
  6.     struct li *next;
  7.     float x;
  8.     float y;
  9. } List;
  10.  
  11. List *g;
  12.  
  13. List *createList(float x, float y)
  14. {
  15.     List *nel = malloc(sizeof(List));
  16.     nel->next = NULL;
  17.     nel->x = x;
  18.     nel->y = y;
  19.  
  20.     return nel;
  21. }
  22.  
  23. void addToList(List *li, float x, float y)
  24. {
  25.     List *w = li;
  26.     while (w->next != NULL)
  27.     {
  28.         w = w->next;
  29.     }
  30.  
  31.     List *nel = malloc(sizeof(List));
  32.     nel->next = NULL;
  33.     nel->x = x;
  34.     nel->y = y;
  35.     w->next = nel;
  36. }
  37.  
  38. void printList(List *li)
  39. {
  40.     List *w = li;
  41.     while (w->next != NULL)
  42.     {
  43.         printf("coords => x: %f, y: %f \n", w->x, w->y);
  44.         w = w->next;
  45.     }
  46.     printf("coords => x: %f, y: %f \n", w->x, w->y);
  47. }
  48.  
  49. int listLength(List *li)
  50. {
  51.     List *w = li;
  52.     int l = 0;
  53.     while (w->next != NULL)
  54.     {
  55.         l++;
  56.         w = w->next;
  57.     }
  58.     l++;
  59.     return l;
  60. }
  61.  
  62. void del(List *li, float x, float y)
  63. {
  64.     List *w = li;
  65.     while (w->next->x != x && w->next->y != y)
  66.     {
  67.         w = w->next;
  68.     }
  69.  
  70.     List *toDel = w->next;
  71.  
  72.     if (toDel->next)
  73.         w->next = toDel->next;
  74.     else
  75.         w->next = NULL;
  76.     free(toDel);
  77. }
  78. int showInterface()
  79. {
  80.  
  81.     printf("Co chcesz teraz zrobic? (zatwierdz enterem)\n 1 - dodaj koordynaty\n 2 - wyswietl koordynaty\n 3 - usun koordynaty\n 4 - sprawdz ilosc koordynatow\n 5- wyjdz\n");
  82.     char c;
  83.     scanf(" %c", &c);
  84.  
  85.     switch (c)
  86.     {
  87.     case '1':
  88.     {
  89.         float x, y;
  90.         printf("podaj wspolrzedna x:\n");
  91.         scanf("%f", &x);
  92.         printf("podaj wspolrzedna y:\n");
  93.         scanf("%f", &y);
  94.         if (!g)
  95.             g = createList(x, y);
  96.         else
  97.             addToList(g, x, y);
  98.     }
  99.     break;
  100.     case '2':
  101.         if (g)
  102.         {
  103.             printList(g);
  104.         }
  105.         else
  106.         {
  107.             printf("nie dodales jeszcze zadnych koordynatow. \n");
  108.         }
  109.  
  110.         break;
  111.  
  112.     case '3':
  113.     {
  114.         float x, y;
  115.         printf("podaj wspolrzedna x:\n");
  116.         scanf("%f", &x);
  117.         printf("podaj wspolrzedna y:\n");
  118.         scanf("%f", &y);
  119.         if (g)
  120.         {
  121.             del(g, x, y);
  122.         }
  123.         else
  124.         {
  125.             printf("lista jest obecnie pusta");
  126.         }
  127.     }
  128.     case '4':
  129.     {
  130.         if (g)
  131.         {
  132.             printf("W bazie jest %i koordynatow.\n", listLength(g));
  133.         }
  134.         else
  135.         {
  136.             printf("baza jest pusta");
  137.         }
  138.     }
  139.     break;
  140.     case '5':
  141.     {
  142.         return 0;
  143.     }
  144.     break;
  145.  
  146.     default:
  147.     {
  148.         printf("nieprawidÅ‚owa opcja\n");
  149.         showInterface();
  150.     }
  151.  
  152.     break;
  153.     }
  154.  
  155.     showInterface();
  156. }
  157. int main()
  158. {
  159.  
  160.     showInterface();
  161.  
  162.     return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement