Docsity

Data Structures and Algorithms: Stack and Doubly Linked List Implementation, Assignments of Information Technology

Toggle sidebar
bg1
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
03/11/2003
Date Received 1st submission
03/11/2003
Re-submission Date
Date Received 2nd submission
Student Name
Nguyễn Văn Trường
Student ID
GCH211359
Class
GCH1107
Assessor name
Đỗ Hồng Quân
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
P4
P5
P6
P7
M4
M5
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Data Structures and Algorithms: Stack and Doubly Linked List Implementation and more Assignments Information Technology in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms Submission date 03/11/2003 Date Received 1st submission 03/11/ Re-submission Date Date Received 2nd submission Student Name Nguyễn Văn Trường Student ID GCH Class GCH1107 Assessor name Đỗ Hồng Quân 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 P 4 P 5 P 6 P 7 M 4 M 5 D3 D

 Summative Feedback:  Resubmission Feedback: Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

I. Design and implementation of Stack ADT and Doubly Linked List

ADT

1. Stack ADT

1.1. define A stack is a linear data structure that operates based on the Last-In, First-Out (LIFO) mechanism, and it is one of the fundamental abstract data structures. It follows a fixed sequence of operations, which means that the order of operations can be either LIFO (Last In, First Out) or FILO (First In, Last Out). To illustrate, think of a stack of plates, where the last plate added will be the first one to be removed. This enables you to access the most recently added item in the stack immediately, just like grabbing the top plate from the stack of plates in one go. (GeeksforGeeks 2023) 1.2. Operations

  • push(int data) add an element to the stack.
  • pop() remove an element from the stack.
  • peek() get the top element of the stack.
  • isEmpty() check if the stack is empty.
  • size() to return the current number of elements in the stack.
  • search(int data) find the last occurrence of the given data in the stack. 1.3. Implementation – Source code

The node structure of a stack in a singly linked list includes two main components: Data: This is the part of the node where you store the specific value you want to put on the stack. Next Pointer: This is a pointer or reference to the next node in the stack. In a singly linked list, each node only knows about the next node in the list.

  • pop() removes the element at the top of the stack. It doesn't require any arguments and just returns the item. Pop source code Pop operation
  • peek() retrieves the uppermost item in the stack without removing it. This operation does not take any arguments and does not modify the stack. Peek source code Peek operation
  • isEmpty() is used to determine whether the stack is devoid of elements. To prevent executing actions on an empty stack, the programmer needs to ensure that the stack is managed properly during push and pop operations in the update phases. This function does not require any arguments and returns a boolean value. isEmpty source code
  • Search(int data) is used to look up the last occurrence of a particular value in the stack and return that value's position in the stack, from the top of the stack. Search source code Search operation

2. Doubly Linked List ADT 2.1. Define A doubly linked list is a more intricate variation of a linked list, where each node includes references to both the previous and the next nodes in the sequence. Consequently, a node in a doubly linked list comprises three components: node data, a pointer to the following node in the sequence (referred to as the "next" pointer), and a pointer to the previous node (known as the "previous" pointer). (javatpoint, 2023) 2.2. Operations

  • addLast(int data) append the specified element to the end of the list
  • removeLast() retrieve and remove the last element of the list
  • addFirst(int data) append the specified element to the beginning of the list
  • removeFirst() retrieve and remove the head (first element) of the list
  • add(int data, int index) insert the specified element at the specified position in this list.
  • remove(int index) remove the element at the specified position in this list.
  • size() returns the current number of elements in the list.
  • search(int data) find the LAST OCCURRENCE of the given data in the list.
  • AddFirst(int data): Add an element to the beginning of the list. addFirst source code addFirst operation
  • addLast((int data): Add an element to the end of the list. addLast source code addLast operation
  • RemoveLast(): removes an element from the end of the list. RemoveLast source code RemoveLast operation

add((int data, int index) adds a new element at a specific position in the list using the index. add cource code add operation

  • Size(): is employed to provide the size of the container, which corresponds to the number of elements it contains. Size source code Size operation

Search(int data) is used to look up the last occurrence of a particular value and return that value's position, from the tail of the stack. Search source code Search operation