hey guys ! i am working on a card game .. so far i have printed the cards and then shuffled them .. Now it says that Each player has a stack of cards. At the beginning of the game before dealing, this stack is empty. When dealing the cards, you have to remove one card at a time from the deck and add it to a stack of cards of each player going clockwise. You have to repeat this until the deck runs out of cards. For example, for a two player game, each player would have 26 cards each. i am new at linked lists so i am having problems with it .. can somebody please help me in dealing with the stack ..
here's my code :

#ifndef CARD_H
#define CARD_H
#include <string>
#include<iomanip>
using namespace std;

class Card 
{
private :
    string suit ;
    string rank ;

public :

    void Setsuit(string Suit)
    {
        suit = Suit ;
    }
    string GetSuit ()
    {
        return suit ;
    }

    void SetRank( string Rank)
    {
        rank = Rank ;
    }

    string GetRank ()
    {
        return rank ;
    }
    void Print_Cards()
    {
        cout << rank << setw(1) <<suit << endl;

    }
};

#endif
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include "Card.h"
using namespace std;

class Deck
{
public :

    Card c[52];

Deck ()                                         
{   
    int index = 0 ;

        for (int i = 2 ; i<=9 ; i++ )
        {
            c[index].Setsuit("H");
            string rank;
            ostringstream convert;
            convert << i;
            rank = convert.str();
            c[index].SetRank(rank);
            index++;
        }
        c[index].Setsuit("H");
        c[index].SetRank("A");
        index++ ;
        c[index].Setsuit("H");
        c[index].SetRank("k");
        index++ ;
        c[index].Setsuit("H");
        c[index].SetRank("Q");
        index++ ;
        c[index].Setsuit("H");
        c[index].SetRank("J");
        index++ ;
        c[index].Setsuit("H");
        c[index].SetRank("10");


        for (int i = 2 ; i<=9 ; i++ )
        {
            c[index].Setsuit("C");
            string rank;
            ostringstream convert;
            convert << i;
            rank = convert.str();
            c[index].SetRank(rank);
            index++;

        }
        c[index].Setsuit("C");
        c[index].SetRank("A");
        index++ ;
        c[index].Setsuit("C");
        c[index].SetRank("k");
        index++ ;
        c[index].Setsuit("C");
        c[index].SetRank("Q");
        index++ ;
        c[index].Setsuit("C");
        c[index].SetRank("J");
        index++ ;
        c[index].Setsuit("C");
        c[index].SetRank("10");
        index++ ;


        for (int i = 2 ; i<=9 ; i++ )
        {
            c[index].Setsuit("S");
            string rank;
            ostringstream convert;
            convert << i;
            rank = convert.str();
            c[index].SetRank(rank);
            index++;

        }
        c[index].Setsuit("S");
        c[index].SetRank("A");
        index++ ;
        c[index].Setsuit("S");
        c[index].SetRank("k");
        index++ ;
        c[index].Setsuit("S");
        c[index].SetRank("Q");
        index++ ;
        c[index].Setsuit("S");
        c[index].SetRank("J");
        index++ ;
        c[index].Setsuit("S");
        c[index].SetRank("10");
        index++ ;
        for (int i = 2 ; i<=9 ; i++ )
        {
            c[index].Setsuit("D");
            string rank;
            ostringstream convert;
            convert << i;
            rank = convert.str();
            c[index].SetRank(rank);
            index++;

        }
        c[index].Setsuit("D");
        c[index].SetRank("A");
        index++ ;
        c[index].Setsuit("D");
        c[index].SetRank("k");
        index++ ;
        c[index].Setsuit("D");
        c[index].SetRank("Q");
        index++ ;
        c[index].Setsuit("D");
        c[index].SetRank("J");
        index++ ;
        c[index].Setsuit("D");
        c[index].SetRank("10");
        index++ ;
    }
    void Print_cards_in_a_Deck()
    {
        for (int i = 0 ; i<52 ; i++ )
        {
            c[i].Print_Cards();
        }
    }

    void Shuffle()
    {
        int first_card, next_card ;
        for (int i = 0 ; i<52 ; i++ )
        {
            Card temp ;
            first_card = rand()%52 ;
            next_card = rand()%52 ;
            temp = c[first_card];
            c[first_card] = c[next_card];
            c[next_card] = temp;

        }

    }

};
#include <iostream>
using namespace std;
#include "Card.h"
#include "Deck.h"
//#include"Node.h"


void main ()
{
    Card c;
    Deck d ;
    c.SetRank("A");
    c.Setsuit("Hearts");

    d.Print_cards_in_a_Deck();
    d.Shuffle();
    cout <<" shuffled cards are " << endl;
    d.Print_cards_in_a_Deck();
    system("pause");
}

You probably need a class called 'Player' which has a stack data member of type card. You can use the c++ stack container which provides you methods to add/remove elements. You don't really need to learn linked list to understand how this container works but you should still learn about linked list anyways since they are so basic and important to understanding a lot of datastructures.

Create as many Players as you need and go about extract cards from the deck and adding to the players decks. That should be the next step.

Also, your main should have the signature 'int main()' and get rid of system("pause"),use std::cin.get() to halt your program if you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.