Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Dodać do kolejki kartę i jej rodzaj, np. As Serce i zrobić wyświetlanie.
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- char *rodzaj[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Joker", "Dama", "Król", "As"};
- char *kolor[] = {"Kier", "Karo", "Pik", "Trefl"};
- struct queue_node{
- char *rodzaj_karty;
- char *kolor_karty;
- struct queue_node *next;
- };
- struct queue_pointers{
- struct queue_node *first, *last;
- } fifo;
- void enqueue(struct queue_pointers *fifo, char rodzaj[], char kolor[])
- {
- struct queue_node *new_node = (struct queue_node*)malloc(sizeof(struct queue_node));
- if(new_node){
- new_node->rodzaj_karty = rodzaj;
- new_node->kolor_karty = kolor;
- new_node->next = NULL;
- if(fifo->first == NULL)
- fifo->first = fifo->last = new_node;
- else{
- fifo->last->next = new_node;
- fifo->last = new_node;
- }
- }
- }
- void print_queue(struct queue_pointers fifo)
- {
- while(fifo.first){
- printf("%s %s\n", fifo.first->rodzaj_karty, fifo.first->kolor_karty);
- fifo.first = fifo.first->next;
- }
- printf("\n");
- }
- int main(void)
- {
- srand(time(NULL));
- // Dodanie przykladowych kart
- for(int i = 0; i < 10; i++)
- enqueue(&fifo, rodzaj[rand() % 13], kolor[rand() % 4]);
- print_queue(fifo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement