2933 - EE2310_Lab13 Scoreboard

Time

2023/12/25 08:15:00 2023/12/25 10:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14187 EE2310_Lab13

14187 - EE2310_Lab13   

Description

Re-write your linked list class as a class template. Our original linked list was defined as follows.

struct node{
    int data;
    struct node *next;
};
typedef struct node node_t;

typedef struct linked_list {
    node_t *head;
    node_t *tail;
}

Now we change it to a class template to hold any class T.

template <class T>
class Linked_list;

template <class T>
class Node {
/*
 * declare the linked list class as friend.
 */
private:
/*
 * put your data members in the private section
 */
};

template <class T>
class Linked_list {
/*
 * put your data members in the private section
 */
};

//---------------------------------------------

Now, define another class Card here as follows

class Card{
public:
/* declare constructors
 * you must overload the << and >> operators
 */

private:
/* data members must be put in the private section
 * you must store the 'suit' and 'face' in some variables
 */
};

To output the special suit symbols, you need to put the following in the beginning of your code

#if defined(_WIN32) || defined(__MSDOS__)
   #define SPADE   "\x06"
   #define CLUB    "\x05"
   #define HEART   "\x03"
   #define DIAMOND "\x04"
#else
   #define SPADE   "\xE2\x99\xA0"
   #define CLUB    "\xE2\x99\xA3"
   #define HEART   "\xE2\x99\xA5"
   #define DIAMOND "\xE2\x99\xA6"
#endif

Then you can simply output symbols like

cout << SPADE;

to output a spade symbol.

We use the following convention to input

S, H, D, C for "Spade", "Heart", "Diamond", and "Club", respectivly.

A, K, Q, J for "Ace", "King", "Queen", and "Jack", respectively. Use T to represent "10"

For example, we use CT to represent the card "The 10 of Club".

//---------------------------------------------
// Do not change main!

int main(){
    Linked_list<Card> my_list;
    
    Card data;
    int input_size;
    /* when you add a node, you add it at the tail */
    
    cin >> input_size;
    
    for(int i=0; i < input_size; ++i) {
        cin >> data;
        my_list.add_node(data);
    }
    my_list.output();
    my_list.reverse();
    my_list.output();
    
    return 0;
}

 

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss