Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct NOD{
- char nume[30], prenume[30], sex;
- int prioritate, varsta;
- struct NOD *next;
- }NOD;
- NOD *creare_nod(){
- NOD *nod_nou = malloc(sizeof(NOD));
- scanf("%s %s %d %c %d", nod_nou->nume, nod_nou->prenume, &nod_nou->varsta, &nod_nou->sex, &nod_nou->prioritate);
- nod_nou -> next = NULL;
- getchar();
- return nod_nou;
- }
- NOD *adauga_persoana(NOD *head){
- NOD *nod_nou = creare_nod(), *nod_curent = head;
- if(head == NULL){
- head = nod_nou;
- return head;
- }
- if(nod_nou -> prioritate < nod_curent -> prioritate){
- nod_nou -> next = head, head = nod_nou;
- return head;
- }
- else{
- for(; nod_curent -> next && nod_curent ->next->prioritate < nod_nou -> prioritate; nod_curent = nod_curent -> next);
- nod_nou -> next = nod_curent -> next;
- nod_curent -> next = nod_nou;
- return head;
- }
- }
- NOD *extragere(NOD *head){
- NOD *nod = head->next;
- printf("%s %s %d %c\n", head -> nume, head -> prenume, head -> varsta, head -> sex);
- free(head);
- return nod;
- }
- int main(){
- char comanda;
- NOD *lista_prioritate = NULL;
- while((comanda = getchar()) != '*'){
- if(comanda == '+'){
- getchar();
- lista_prioritate = adauga_persoana(lista_prioritate);
- }
- else{
- lista_prioritate = extragere(lista_prioritate);
- getchar();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement