Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream.h>
- #include <math.h>
- #include <stdio.h>
- #include <time.h>
- // -Structuri
- struct nod
- {
- int val;
- nod *next;
- };
- struct coada
- {
- nod *vf, *sf;
- int vid;
- };
- // -Definiri
- void init(coada);
- void deal();
- void add(coada & , int);
- void extract(coada, int &);
- void afis_before(coada, coada);
- void afis_after(coada);
- coada p1,p2;
- int main()
- {
- init(p1);
- init(p2);
- deal();
- afis_before(p1,p2);
- return 0;
- }
- void init(coada c)
- {
- c.vf=NULL;
- c.sf=NULL;
- c.vf->next=NULL;
- c.sf->next=NULL;
- }
- void deal()
- {
- int i=1,v[15],card;
- for(i=1;i<=14;i++)
- v[i]=4;
- //Jucator 1
- randomize();
- for(i=1;i<=26;i++)
- {
- xx: card=rand()%13+2;
- if(!v[card]) goto xx;
- else
- {
- v[card]--;
- add(p1,card);
- }
- }
- //Jucator 2
- randomize();
- for(i=1;i<=26;i++)
- {
- yy: card=rand()%13+2;
- if(!v[card]) goto yy;
- else
- {
- v[card]--;
- add(p2,card);
- }
- }
- }
- void add(coada &c, int x)
- {
- nod *n=new(nod);
- n->val=x;
- n->next=NULL;
- if(!c.vf) c.vf=n;
- else c.sf->next=n;
- c.sf=n;
- }
- void extract(coada c, int &x)
- {
- nod *n;
- n=c.vf;
- x=c.vf->val;
- if(c.vf==c.sf) c.vid=0;
- else
- c.vf=c.vf->next;
- delete(n);
- }
- void afis_before(coada c1, coada c2)
- {
- nod *n;
- n=c1.vf;
- cout<<"Player 1: ";
- while(n)
- {
- if(n->val!=11) cout<<n->val<<" ";
- else cout<<"A ";
- n=n->next;
- }
- cout<<endl;
- n=c2.vf;
- cout<<"Player 2: ";
- while(n)
- {
- if(n->val!=11) cout<<n->val<<" ";
- else cout<<"A ";
- n=n->next;
- }
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement