[CSC10004 - DSA] Exercise 1 - Stack and Queue
[CSC10004 - DSA] Exercise 1 - Stack and Queue
Exercise 1
1 Description
Stack and Queue are two fundamental data structures in programming. Stack allows adding and
retrieving elements according to the LIFO (Last In, First Out) principle, while Queue allows adding
and retrieving elements according to the FIFO (First In, First Out) principle. In this Exercise 1,
you are required to implement these two data structures, using struct and template.
and functions:
• push: an operator to push a new item into stack. Print to the console if the stack is full.
Please note that the program should be organized into (at least) 3 separate files, including stack.h
(containing the declaration of the stack), stack.cpp (containing the implementation for the stack),
and main.cpp (to use the stack as a library).
Figure 1 and Figure 2 below are examples of stack.h and stack.cpp files.
In main.cpp, create a menu to test the stack operators (pop and push). Run the program with
normal test cases, when the stack is empty, and when the stack is full. Capture the results and
include them in the report.
• top: a pointer to the top node of the stack. The node here is a simple struct, including data
and a pointer to another node.
For example:
template <typename T>
struct Node
{
T data;
Node* next;
};
and functions:
• push: an operator to push a new item into stack. Print to the console if the stack is full.
Similar to when implementing the stack (array version), please organize the program into (at least)
3 separate files (stack.h, stack.cpp, and main.cpp). In main.cpp, create a menu to test the stack
operators (pop and push). Run the program with normal test cases, when the stack is empty, and
when the stack is full. Capture the results and include them in the report.
Figure 3 below is an example of stack.h file for stack using linked list.
2 Submission
Source code folder and Report file must be contributed in the form of a compressed file (.zip, .rar)
and named according to your Student ID. For example:
StudentID.zip
Source
Report.pdf
2.2 Report
The report must fully give the following information:
• Self-evaluation.
• Detailed experiments.
• The report needs to be well-formatted and exported to PDF. If there are figures cut off by
the page break, etc., points will be deducted.
3 Assessment
No. Details Score
1 Stack (Array version) 15%
2 Stack (Linked List version) 15%
3 Queue (Array version) 15%
4 Queue (Linked List version) 15%
5 Recursive versions 20%
6 Report 20%
Total 100%
4 Notices
Please pay attention to the following notices:
• Any plagiarism, any tricks, or any lie will have a 0 point for the course grade.