0% found this document useful (0 votes)
50 views

Lab06 Stack Queue

This document provides instructions for Lab 06 on stacks and queues. Students are asked to complete assignments on implementing stacks and queues as arrays and linked lists. Specific tasks include creating stack and queue data structures with functions like push, pop, enqueue, dequeue. Students must also submit a report on using stacks in the C++ Standard Template Library and describe one individual project task they completed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Lab06 Stack Queue

This document provides instructions for Lab 06 on stacks and queues. Students are asked to complete assignments on implementing stacks and queues as arrays and linked lists. Specific tasks include creating stack and queue data structures with functions like push, pop, enqueue, dequeue. Students must also submit a report on using stacks in the C++ Standard Template Library and describe one individual project task they completed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS162 – Programming Techniques

Lab 06
Stack & Queue

Cảm ơn thầy Trần Duy Quang đã cung cấp template cho môn học

Department of Software Engineering-FIT-VNU-HCMUS


CS162 – Programming Techniques Lab06 – Stack & Queue

1
Notes
Create a single solution/folder to store your source code in a week.
Then, create a project/sub-folder to store your source code of each assignment.
The source code in an assignment should have at least 3 files:
• A header file (.h): struct definition, function prototypes/definition.
• A source file (.cpp): function implementation.
• Another source file (.cpp): named YourID_Ex01.cpp, main function. Replace 01 by id of an
assignment.
Make sure your source code was built correctly. Use many test cases to check your code before
submitting to Moodle.

2
CS162 – Programming Techniques Lab06 – Stack & Queue

2
Content
In this lab, we will review the following topics:
• Stack, queue and their applications.

3
CS162 – Programming Techniques Lab06 – Stack & Queue

3
Assignments
A: YY: 01
H: YY: 01 (choose 1 in [3.1, 3.2], and 1 in [3.3, 3.4])

3.1 Stack as an Array


Implement a stack of integer with the following functions:
1. init(s, capacity): create an empty stack.
2. push(s, x): add an integer to stack.
3. pop(s): remove the top element from stack, return the value of the removed one.
4. isEmpty(s): check whether a stack is empty or not.
5. empty(s): make a stack empty.
6. size(s): get the number of elements in the stack.

struct Stack{
int *data; // dynamic array
int top; // index of top element
int capacity; // size of stack
};

3.2 Stack as a Linked List


Implement a stack of integer with the following functions:
1. init(s, capacity): create an empty stack.
2. push(s, x): add an integer to stack.
3. pop(s): remove the top element from stack, return the value of the removed one.
4. isEmpty(s): check whether a stack is empty or not.
5. empty(s): make a stack empty.
6. size(s): get the number of elements in the stack.

struct Node{
int data;
Node *next;
};

struct Stack{

4
CS162 – Programming Techniques Lab06 – Stack & Queue

Node *head;
int capacity;
};

3.3 Queue in an Array


Implement a queue of integer with the following methods:
1. init(s, capacity): create an empty queue.
2. enqueue(s, x): add an integer to queue.
3. dequeue(s): remove the oldest element from queue, return the value of the removed one.
4. isEmpty(s): check whether a queue is empty or not.
5. empty(s): make a queue empty.
6. size(s): get the number of elements in the queue.
7.

struct Queue
{
int *data;
int in;
int out;
int capacity;
};

3.4 Queue in a Linked List


Implement a queue of integer with the following methods:
1. init(s, capacity): create an empty queue.
2. enqueue(s, x): add an integer to queue.
3. dequeue(s): remove the oldest element from queue, return the value of the removed one.
4. isEmpty(s): check whether a queue is empty or not.
5. empty(s): make a queue empty.
6. size(s): get the number of elements in the queue.

struct Queue{
Node *head;
Node *tail;
int capacity;
};

5
CS162 – Programming Techniques Lab06 – Stack & Queue

3.5 Decimal base to binary, hex base


1. Convert an unsigned integer from decimal base to binary base, and vice versa
2. Convert an unsigned integer from decimal base to hex base, and vice versa

3.6 Stack in STL


Write a report to show how to use stack in C++ Standard Template Library
https://www.cplusplus.com/reference/stack/stack/

3.7 Individual Project Report


Write a short paragraph (at least 10 sentences) to describe 1 task you have completed in the project in
this week (2021-04-06 – 2021-04-12). A task must be done only by 1 member.
Your report should answer the following questions:
What is the name of your task?
Write a short description about this task.
What is the start date that you began to work on this task and the end date that you finished this task?
What is the number of working hours you spent for this task?
Screenshot the commit in your Github/Bitbucket/GitLab project.

You might also like