0

Can anyone help me how to write the following codes in different ways. I used Linked List.

template<class Item>
ttt<Item>::ttt()
{
        square=0;
        board=new node<Item>;
        for (Item i='9'; i>=1; i--)
        {
            list_head_insert(board,i);
        }
}

template<class Item>
void ttt<Item>::clear()
    {
        list_clear(board);
        square=0;
        board=new node<Item>;
        for (Item i='9'; i !='0'; i--)
        {
            list_head_insert(board,i);
        }
    }

template<class Item>
void ttt<Item>::set_position(int order_pl, Item X_or_O)
    {
        if (num(order_pl)!='X'||num(order_pl)!='O')
        {
            list_locate<node<Item>*,int>(board,order_pl)->set_data(X_or_O);
            ++square;
        }
    }

template<class Item>
bool ttt<Item>::has_won(const Item& X_or_O)
    {
        if((num(1)==X_or_O&&num(2)==X_or_O&&num(3)==X_or_O)
            ||(num(4)==X_or_O&&num(5)==X_or_O&&num(6)==X_or_O)
            ||(num(7)==X_or_O&&num(8)==X_or_O&&num(9)==X_or_O)
            ||(num(1)==X_or_O&&num(4)==X_or_O&&num(7)==X_or_O)
            ||(num(5)==X_or_O&&num(2)==X_or_O&&num(8)==X_or_O)
            ||(num(3)==X_or_O&&num(6)==X_or_O&&num(9)==X_or_O)
            ||(num(1)==X_or_O&&num(5)==X_or_O&&num(9)==X_or_O)
            ||(num(3)==X_or_O&&num(5)==X_or_O&&num(7)==X_or_O))
            return true;
        return false;
    }

template <class Item>
int ttt<Item>::size_filled()
    {
        return square;
    }

template<class Item>
void ttt<Item>::draw()
    {
        cout<<endl;
        cout<<endl<<"  "<<num(1)<<" | "<<num(2)<<" | "<<num(3)<<endl;
        cout<<" "<<"---|---|---"<<endl;
        cout<<"  "<<num(4)<<" | "<<num(5)<<" | "<<num(6)<<endl;
        cout<<" "<<"---|---|---"<<endl;
        cout<<"  "<<num(7)<<" | "<<num(8)<<" | "<<num(9)<<endl;
        cout<<endl;
        cout<<endl;
    }



template<class Item>
bool ttt<Item>::is_occupied(int X_or_O)
    {
        if (num(X_or_O)=='X'||num(X_or_O)=='O')
            return true;
        else 
            return false;
    }

template<class Item>
Item ttt<Item>::num(int position)
{
        return list_locate<node<Item>*,int>(board,position)->data();
}

This is the part of my program. anyboy who know how to write this code in Linked List..plzz help me. Thanks in advance.

Edited by pyTony: fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by people123
0

Please use [code=c++] [/code] around your code. Thanks[noparse]

around your code.
Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.