Data Structures (Cs 202) in C++
Data Structures (Cs 202) in C++
LAB 1
WELCOME ! This is your first lab in data structures and is meant to ease you into the kind of
work(implementing data structures and using them :p) that you might be doing in assignments, labs
and projects through the duration of this course.
In this lab you are going to implement your own Stack and Queue classes with their
appropriate methods and then maybe go for an implementation of a Hashtable to score 40% bonus
points to be compensated in any of your labs.
First you have been given a class called “Card” in a project file.
Using this Card class. Make 2 separate decks of cards...(Total 52 + 52 cards) [2 static(fixed size) arrays]
Stack class will be a dynamic array of exactly the size of elements that are inside the array, so you
shall have to be careful with the assignment of memory! VERY VERY CAREFUL
Queue class will also be a dynamic array of exactly the size of elements that are inside the array, so
you shall have to be careful with the assignment of memory! VERY VERY CAREFUL.
As some of you may be rusty from your c++ coding after the winter break, here is a refresher on how
to make oneD Dynamic arrays in C++
http://fydo.net/gamedev/dynamic-arrays
[Type in your own code, otherwise you will not understand this and will get caught in memory errors]
Stack has 3 functions, push, pop and peep. Implements Last In First Out (LIFO)
You are expected to know exactly how push, pop and peep work for Stacks
Please make separate .h files and .cpp files otherwise you shall be penalized
Queue has 2 functions push and pop, implements First In First Out (FIFO)
You are expected to know exactly how push and pop work for Queues
Please make separate .h files and .cpp files otherwise you shall be penalized
TASKS:
Now Push all cards from 1 deck (the static arrays we made earlier) into a stack and push all cards from
other deck into a Queue.
void push (Card c).....pushes the card into the stack at the top
Card pop ().....returns the card on the top of the stack and removes it from the stack
void peep () … returns the card on the top of the stack but does NOT remove it
void print ()....prints all cards in the stack
Repeat the steps 1&2 until your stack and queue are empty (They will both be empty after
nd
the 52 round of popping has taken place!)
Use Simple Hashing function of value mode 8 to decide where (which stack) to enter a couple of cards
from stack S.
Now Tell the number of steps it takes to tell all cards present in the hashtable! Note, no pairs are lost.