0% found this document useful (0 votes)
51 views3 pages

Data Structures (Cs 202) in C++

This document provides instructions for a data structures lab assignment involving implementing stacks and queues in C++. Students are asked to: 1. Implement stack and queue classes with appropriate methods like push(), pop(), etc. and use them to store cards from two decks. 2. Pop cards from the stack and queue, comparing their values, and push matching cards to a final stack. 3. Optionally implement a bonus hash table using an array of stacks for additional points.

Uploaded by

hammadm_8
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

Data Structures (Cs 202) in C++

This document provides instructions for a data structures lab assignment involving implementing stacks and queues in C++. Students are asked to: 1. Implement stack and queue classes with appropriate methods like push(), pop(), etc. and use them to store cards from two decks. 2. Pop cards from the stack and queue, comparing their values, and push matching cards to a final stack. 3. Optionally implement a bonus hash table using an array of stacks for additional points.

Uploaded by

hammadm_8
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Card has two variables....an integer value and an integer suite

Using this Card class. Make 2 separate decks of cards...(Total 52 + 52 cards) [2 static(fixed size) arrays]

Now make a shuffle function..this shuffles your Decks(arrays) of Cards.


Call this function on your both decks several times...so the decks are properly shuffled

This function has to be defined in the “MainMethod.cpp” file.


And should have the signature void shuffleDeck(Card aDeck[]) (20 POINTS)

Now Make a “Stack” class and a “Queue” class,

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.

Their functions shall determine the nature of the data Structures.

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.

Your Stack has following methods: (30 POINTS)

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

Your Queue has following methods: (30 POINTS)

void push (Card c).....pushes the card into the queue


Card pop ().....returns the first card (or u can say at index 0) and removes it
print ()...print all cards

OK....So far so good

TASK: (20 POINTS)


1- Now pop out 1 card from Stack and pop out 1 card from Queue.
2- If the value (not necessarily suite) of both cards is equal....Push both cards in a new Stack
called final Solution
3- if the value is not same for both the cards then discard both of them.

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!)

Print stack final Solution... and that’s it....u r done =D

BONUS: (40 POINTS) (MAY BE SUBMITTED TILL SUNDAY)


Make the following kind of a hashtable.

Make an oneD array of Stacks (this in essence makes a 2D array)


The array should be size 8,

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.

You might also like