





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms Submission date 12/3/2023 Date Received 1st submission 12/3/ Re-submission Date Date Received 2nd submission Student Name Luu^ Ngoc^ Hai^ Student ID GCH Class GCH 1006 Assessor name Do Hong Quan Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Grading grid
Assignment Brief and Guidance Scenario As assigned by the manager, in this work, you are asked to provide proper implementations and evaluations for the following tasks. (a) Implement a stack by a "linked list" that follows this graph representation below as underlying data structure. (b) Implement a queue by a "doubly-linked list" that follows this graph representation below as underlying data structure. (c) Implement and compare two solutions to reverse a Stack, that are using Recursion and without Recursion. The implemented operation should take a Stack as the input. Consider using only those data structures that are already implemented in Q.a and Q.b. Note that: (1) Most defined operations of Stack and Queue as stated in Assignment 1 should be implemented. (2) Errors should be handled carefully by exceptions and in the report some tests should be executed to prove the correctness of algorithms / operations. (3) Besides, in the report, the work should evaluate the use of ADT in design and development, including the complexity, the trade-off and the benefits.
Figure 2: Description of Node Line: 8 + 9 Declare Data and NextNode are the two components of a node. The author assigns two values to the starting value. Both Data and NextNode are Null. To put it another way, the array of values contains nothing at first. b. Operations How the stack works as follows: o void push ( item) : adds a new item to the stack's top. It requires the item but does not provide a response; o pop() : pops the item at the top of the stack. It returns the item with no arguments. The stack has been changed. o peek() retrieves the stack's top item but does not delete it. There are no parameters required. The stack isn't changed. o boolean isEmpty() : Determines whether or not the stack is empty. It has no inputs and outputs a boolean value. When the stack is empty, return "true." o int size() : Returns the number of accessible stack items (Top+1). It has no inputs and outputs an integer. c. Implementation - My Stack interface: The author created NextNode to mark a new Node added to MyStack. The author initialize the variable count = the Nodes that MyStack has.MyStack.Max_size: is the maximum number of items that MyStack scan store that the user enters from the screen.
Figure 3: Stack interface
Figure 5: Description of line code 40 to 47.
2. Queue a. Introduction A queue is a linear structure that executes tasks in a predetermined sequence. First in, first out (FIFO) refers to the order in which the pieces are placed in the Queue. A queue is a line of customers waiting for a resource, with the first client being served first. The stack and queue are dropped in the various procedures. The most recently added item is taken out of the stack, whereas the most recently added item is taken out of the queue. The author will discuss Queues' uses and construct a queue in the parts that follow. The ADT algorithm is built on a double topology. Figure 6: Double LinkedList
Because it is similar to Stack, Queue also has the same way of adding as that of Stack. The author on lines 27 to 30 has created a test condition in Methol isFull(). In isFull() will be responsible for checking if the number of elements in the array is greater than the allowed element. if greater than the element returns: Queue is Overflow and true. If it is not greater than the given element, it will just return false and continue running the following statements. In line 34, the author put another statement to check if this function is empty or not, if empty, head will point to that element. If the author only adds 1 element. Then Head = newNode. Figure 7: add 1 data in Queue
And in case you want to add elements to the existing elements. Then head will project on the newly added element, tail.next = newNode. newNode.prev = tail and increment count by 1. Figure 8: Add 1 data to many data in Queue
Pickfirst (): Method Pickfirst created with the purpose of saving the initial value for the array. Start method Pickfirst will check if function is empty or not if empty function will return Stack is empty and value -
If the function is not empty, it will return the head value of the array (Head).
The size() method returns a counter function: that counts the elements in the array. This function is quite special in case if the function has no value then it will return zero by itself and don't need to give anything like other methods.
Boolean isFull() method as mentioned above this function helps to check whether the newly added elements in the array exceed the specified Max_Capacity? If it passes will return Queue is overflow and true. Otherwise, it will return False. II. Implement error handling and report test results (P5)
1. Testing plan No Scope Operation (^) Testing type Input Expected Output Actual Output Status 1 Stack Push(int Normal MyStack[2,3,5] MyStack[8,2,3,5] The same as Pass data) push(8); size()=4 expected output peek():return 8 2 Push(int Normal MyStack[] MyStack[8,] The same as Pass data) (^) push(8); size()= peek():return 8 expected output 3 Push(int Data MyStack[2,3,5] Printf(“Incorrect program stop Fail data) (^) validation push(@@@); input”) 4 Push(int^ Normal MyStack[8,2,3,5]^ MyStack[8,2,3,5]^ The^ same^ as^ Pass data) Max_element=4 size()=4 expected output push(10); peek():return 8 “Overflow” 5 Pop() Normal MyStack[2,3,5] MyStack[3,5] The same as Pass pop(); pop():return 2 expected output size()= peek():return 3