Assignment 4: Stacks and Queues
Prerequisites
- Required: Read the [Part1: Struct, Stacks, Linked Lists, and Queues]
- Required: Read [More on Structs, Linked Lists, Naming Conventions, Const-correctness, Build Systems, and Git for Teams], the following sections:
- Optional: The rest of the notes [More on Structs, Linked Lists, Naming Conventions, Const-correctness, Build Systems, and Git for Teams]
Abstract Data Type Overview
Abstract Data Types (ADT), as explained earlier are abstract specifications of a structure; ADT do not specify a particular implementation. ADTs we have been through so far:
- List
- Stack
- Queue
While concrete data types that we use to implement the above ADTs are:
- Arrays
- Linked Lists
Objectives
- Collaboration in groups, using git.
- Implement concrete linked list of few premitive data types (
int
,double
, andchar
). - Implement stacks of few primitive data types, using:
- Arrays.
- Linked Lists.
- Implement queues of few primitive data types, using:
- Linked Lists.
- Arrays (Bonus).
- Use your new data structures in interesting applications.
Clone Your Asssignment
Join your group assignment from this link
Deadlines
Soft deadline Tuesday of 13/3, at 11:59 PM.
Before soft deadline you are ecncouraged to ask your TA for guidance concerning any difficulties working on the assignment.
Hard deadline Thursday of 15/3, at 11:59 PM.
Guidance are not offered after the soft deadline. Just make sure to submit before the hard deadline to avoid late penalties.
Grading Policy
Grades will be determined by:
- 50% Group score: each group will receive a score to be assigned to each member in that group.
- Reasonable Load distribution.
- Seamless collaboration on the same repository.
- Overall consistency (see naming conventions of the notes of Thursday of 1st of March).
- 50% Individual score: depends on the contribution of each member in the group.
Bonus Grades
Bonus grades will be assigned to the whole group by considering the following points:
- Adoption of KISS and DRY solutions.
- Representative and optimum use of:
struct
namespace
- const-correctness
- Basic OOP (see Thursday of 1st of March notes on methods vs. functions).
- overusing certain feature has negative impact, so be careful and rational.
Assignment 4 Requirements
A submission won’t be accepted (zero score) if any requirement is not satisfied.
Concrete Implementation Linked List
Supported Operations:
- insertion at front
insertFront
. - insertion at back
insertBack
. - remove front
removeFront
. - remove back
removeBack
. - remove the kth-element
removeAt
. - return front
front
. - return back
back
. - get arbitrary kth-element
getAt
. - remove nodes with given data
filter
. - is empty
isEmpty
? - size of the linked list
size
. - printAll
printAll
. - delete the whole list from the heap
clear
.
You can use the following function prototypes (declarations), for integers linked list.
void insertFront( IntegersLL &list , int data );
void insertBack( IntegersLL &list, int data );
void removeFront( IntegersLL &list );
void removeBack( IntegersLL &list );
void removeAt( IntegersLL &list , int index );
int front( IntegersLL &list );
int back( IntegersLL &list );
int getAt( IntegersLL &list, int index );
void filter( IntegersLL &list, int data );
bool isEmpty( IntegersLL &list );
int size( IntegersLL &list );
void printAll( IntegersLL &list );
void clear( IntegersLL &list );
Implement the linked list for int
, double
, and char
.
Stack
Supported Operations:
push
.pop
.size
.- is empty?
isEmpty
. - return front
front
(LIFO). - delete the whole stack
clear
.
You can use the following function prototypes (declarations), for stack of integers.
void push( IntegersStack &stack , int data );
int pop( IntegersStack &stack );
int front( IntegersStack &stack );
bool isEmpty( IntegersStack &stack );
int size( IntegersStack &stack );
void clear( IntegersStack &stack );
- Implement stacks of
char
andint
using linked lists. - Implement stacks of
char
andint
using arrays.
Queue
Supported Operations:
enqueue
.dequeue
.size
.isEmpty
.- return
front
(FIFO), without dequeue. - delete the whole queue
clear
.
You can use the following function prototypes (declarations), for queue of integers.
void enqueue( DoublesQueue &queue , int data );
int dequeue( DoublesQueue &queue );
int front( DoublesQueue &queue );
bool isEmpty( DoublesQueue &queue );
int size( DoublesQueue &queue );
void clear( DoublesQueue &queue );
- Implement queues of
char
anddouble
using linked lists. - Bonus: implement queues of
char
anddouble
using arrays.
Applications
- A1: Using stack of
int
, make an application (i.e a source file withmain
funciton) that solves The Stock Span Problem. - A2: Using stack of
char
, make an application (i.e source file withmain
function) that validates the balancing of prenthesis in a string.
Examples:
- Input:
"()"
- Output:
"balanced"
- Output:
- Input:
"())"
- Output:
"not balanced"
- Output:
- Input:
"(()"
- Output:
"not balanced"
- Output:
- Input:
"()((()(((())))))"
- Output:
"balanced"
- Output:
- A3: Your are required to develop some interesting and useful application that depends on the queues you implemented earlier. It is preferably to apply some useful logic on biological data. Remember to keep it simple and stupid.
Guidelines
These are suggested guidelines to follow, i.e not mandatory.
Collaboration
- To avoid conflicts, each member would create a unique header file (e.g
member3.hpp
), to implement his share in the task. - After creating (or renaming) a file (e.g
member3.hpp
):git add member3.hpp
git commit -a -m "add/rename file for member3"
git pull origin master
git push origin master
- It is recommended that each member wrap his/her own work in a
namespace
representing the data structure he/she works on. For example,lists
,stacks
, andqueues
. - At the begining, you need for a meeting to settle on a plan for collaboration on the remote repository.
- It is recommended that each team has a leader, who distributes the load, writes any necessary skeleton codes.
Declaring namespace across mutiple files
Assume that both member1 and member2 implement functions related to queue in member1.hpp
and member2.hpp
files, respectively. It is perfectly Okay that they declare the same namespace
of queue
.
// member1.hpp
// ..
// ..
// ..
namespace queue
{
void enqueue( IntegerLL &l , int element )
{
// Some logic
}
}
// member2.hpp
// ..
// ..
// ..
namespace queue
{
void enqueue( CharLL &l , char element )
{
// Some logic
}
}