Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct li
- {
- struct li *next;
- float x;
- float y;
- } List;
- List *g;
- List *createList(float x, float y)
- {
- List *nel = malloc(sizeof(List));
- nel->next = NULL;
- nel->x = x;
- nel->y = y;
- return nel;
- }
- void addToList(List *li, float x, float y)
- {
- List *w = li;
- while (w->next != NULL)
- {
- w = w->next;
- }
- List *nel = malloc(sizeof(List));
- nel->next = NULL;
- nel->x = x;
- nel->y = y;
- w->next = nel;
- }
- void printList(List *li)
- {
- List *w = li;
- while (w->next != NULL)
- {
- printf("coords => x: %f, y: %f \n", w->x, w->y);
- w = w->next;
- }
- printf("coords => x: %f, y: %f \n", w->x, w->y);
- }
- int listLength(List *li)
- {
- List *w = li;
- int l = 0;
- while (w->next != NULL)
- {
- l++;
- w = w->next;
- }
- l++;
- return l;
- }
- void del(List *li, float x, float y)
- {
- List *w = li;
- while (w->next->x != x && w->next->y != y)
- {
- w = w->next;
- }
- List *toDel = w->next;
- if (toDel->next)
- w->next = toDel->next;
- else
- w->next = NULL;
- free(toDel);
- }
- int showInterface()
- {
- 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");
- char c;
- scanf(" %c", &c);
- switch (c)
- {
- case '1':
- {
- float x, y;
- printf("podaj wspolrzedna x:\n");
- scanf("%f", &x);
- printf("podaj wspolrzedna y:\n");
- scanf("%f", &y);
- if (!g)
- g = createList(x, y);
- else
- addToList(g, x, y);
- }
- break;
- case '2':
- if (g)
- {
- printList(g);
- }
- else
- {
- printf("nie dodales jeszcze zadnych koordynatow. \n");
- }
- break;
- case '3':
- {
- float x, y;
- printf("podaj wspolrzedna x:\n");
- scanf("%f", &x);
- printf("podaj wspolrzedna y:\n");
- scanf("%f", &y);
- if (g)
- {
- del(g, x, y);
- }
- else
- {
- printf("lista jest obecnie pusta");
- }
- }
- case '4':
- {
- if (g)
- {
- printf("W bazie jest %i koordynatow.\n", listLength(g));
- }
- else
- {
- printf("baza jest pusta");
- }
- }
- break;
- case '5':
- {
- return 0;
- }
- break;
- default:
- {
- printf("nieprawidłowa opcja\n");
- showInterface();
- }
- break;
- }
- showInterface();
- }
- int main()
- {
- showInterface();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement