Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.c
- #include "functii.h"
- int main(){
- int nr_jucatori;
- scanf("%d", &nr_jucatori);
- NOD *jucator;
- for(int i=0; i<nr_jucatori; i++){
- jucator = creare_nod(jucator);
- }
- afisare(jucator);
- while(jucator->next){
- jucator = citire_carti(jucator);
- jucator = eliminare_jucator(jucator);
- afisare(jucator);
- }
- return 0;
- }
- // functii.h
- #include "functii.h"
- NOD * creare_nod(NOD *head){
- NOD *nou = malloc(sizeof(NOD));
- scanf("%s", nou->nume);
- nou->next = NULL;
- if(head == NULL)
- head = nou;
- else{
- NOD *curent = head;
- for( ; curent->next; curent=curent->next);
- curent->next = nou;
- }
- return head;
- }
- NOD *citire_carti(NOD *head){
- NOD *curent = head;
- for( ; curent!=NULL; curent=curent->next)
- scanf("%d", &curent->carte);
- return head;
- }
- NOD *stergere_nod(NOD *head, int poz){
- NOD *nod = head;
- if(poz == 0){
- head = head->next;
- free(nod);
- }
- else{
- for(int i = 0; i<poz-1; i++) nod = nod->next;
- NOD *nod_sters = nod->next;
- nod -> next = nod -> next -> next;
- free(nod_sters);
- }
- return head;
- }
- NOD *eliminare_jucator(NOD *head){
- int poz = 0, mini = head->carte;
- NOD *nod = head ->next;
- for(int i = 1; nod; nod = nod->next, i++)
- if(mini > nod->carte)
- mini = nod->carte, poz = i;
- return stergere_nod(head, poz);
- }
- void afisare(NOD *head){
- NOD *nod = head;
- for(; nod; nod=nod->next)
- printf("%s\n", nod->nume);
- }
- //functii.c
- #include "functii.h"
- NOD * creare_nod(NOD *head){
- NOD *nou = malloc(sizeof(NOD));
- scanf("%s", nou->nume);
- nou->next = NULL;
- if(head == NULL)
- head = nou;
- else{
- NOD *curent = head;
- for( ; curent->next; curent=curent->next);
- curent->next = nou;
- }
- return head;
- }
- NOD *citire_carti(NOD *head){
- NOD *curent = head;
- for( ; curent!=NULL; curent=curent->next)
- scanf("%d", &curent->carte);
- return head;
- }
- NOD *stergere_nod(NOD *head, int poz){
- NOD *nod = head;
- if(poz == 0){
- head = head->next;
- free(nod);
- }
- else{
- for(int i = 0; i<poz-1; i++) nod = nod->next;
- NOD *nod_sters = nod->next;
- nod -> next = nod -> next -> next;
- free(nod_sters);
- }
- return head;
- }
- NOD *eliminare_jucator(NOD *head){
- int poz = 0, mini = head->carte;
- NOD *nod = head ->next;
- for(int i = 1; nod; nod = nod->next, i++)
- if(mini > nod->carte)
- mini = nod->carte, poz = i;
- return stergere_nod(head, poz);
- }
- void afisare(NOD *head){
- NOD *nod = head;
- for(; nod; nod=nod->next)
- printf("%s\n", nod->nume);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement