Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define EXIT_SUCCESS 0
- #define ALLOCATION_ERROR -1
- typedef struct osoba *position;
- typedef struct osoba
- {
- char ime[20];
- char prezime[20];
- int god_rod;
- position next;
- }_OSOBA;
- position CreateNode(position);
- position Insert(position);
- position InsertLast(position);
- void Print(position);
- position FindLast(position);
- position FindbyName(position);
- void Delete(position);
- position FindBefore(position head, position p);
- int main(int argc, char *argv[])
- {
- position head;
- head = NULL;
- int n;
- puts("Broj clanova liste:");
- scanf("%d", &n);
- getchar();
- while (n > 0)
- {
- head = Insert(head);
- n--;
- }
- Print(head);
- Delete(head);
- Print(head);
- return EXIT_SUCCESS;
- }
- position CreateNode(position p)
- {
- position q;
- q = NULL;
- q = (position)malloc(sizeof(_OSOBA));
- if (q == NULL)
- exit(-1);
- return q;
- }
- position Insert(position p)
- {
- position q;
- q = CreateNode(p);
- q->next = p;
- puts("Ime:");
- fgets(q->ime, 50, stdin);
- puts("Prezime:");
- fgets(q->prezime, 50, stdin);
- puts("Godina rodenja:");
- scanf("%d", &(q->god_rod));
- getchar();
- return q;
- }
- void Print(position p)
- {
- while (p != NULL)
- {
- puts(p->ime);
- puts(p->prezime);
- printf("%d", p->god_rod);
- printf("\n");
- p = p->next;
- }
- return;
- }
- position InsertLast(position p)
- {
- position last, q;
- last = FindLast(p);
- q = Insert(NULL);
- last->next = q;
- return p;
- }
- position FindLast(position p)
- {
- while (p->next != NULL)
- p = p->next;
- return p;
- }
- position FindbyName(position p)
- {
- char prez[50];
- puts("Trazeno prezime:");
- fgets(prez, 50, stdin);
- while (p != NULL)
- {
- if (strcmp(p->prezime, prez) == 0)
- {
- printf("Nadeno je prezime: %s", p->prezime);
- }
- p = p->next;
- }
- return p;
- }
- //position FindBefore(position p)
- //{
- // position q = NULL;
- //
- // q = FindbyName(p);
- //
- // while (p->next != NULL && p->next != q)
- // {
- // p = p->next;
- //
- // }
- // return p;
- //}
- void Delete(position p)
- {
- position q;
- q = FindbyName(p);
- while (p->next != NULL && p->next != q)
- {
- p = p->next;
- }
- p->next = q->next;
- free(q);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement