• Home
  • University of the People
  • Data Structures (proctored course) CS 3303
  • Data Structures Implementation using Linked List

Data Structures Implementation using Linked List

University of the People CS3303 - Data Structures Instructor - Chinu Singla Unit 3 Programming Assignment For the third week programming assignment, we were asked to implement our own stack structure using either a linked list or array data structure. The stack should also contain methods or equivalent code that can push items onto the stack or pop items off the stack. It should also contain code that will push three items into the stack and a code that will pop the items from the stack and report each item by writing a message to the console. So I implemented this stack by using the linked list data structure. When we analyze the code using the asymptotic analysis techniques, we will understand that the linked list based implementation of stack will have an upper bound of a linear scale. We can represent it as O(n) for a stack with n items inserted into it. This is because we can assume that the pushing and popping process will take a constant time so in the code a couple of items will be pushed and they will be poped and this is simple algorithm without any nested loops or similar patterns that will increase the growth rate as the value of n increases. So The cost of a single push function is O(1). Also, the cost of a single pop function is O(1). Finally, the cost of pushing n items onto a stack or popping n items from a stack is O(n). My code for the linked list data structure based stack is the following. class Node{ Node ptr; int value; public Node(int value) { this.value = value; } } public class CreateLinkedList { private static int size; public static Node top; public static Node new_top; public static void main(String[] args) { push(2); push(1); push(0); popO; popO; popO; public static void print(int n){ public void clear0{ top = null; size = 0; }; public static void push(int it) { new_top = new Node(it); new_top.ptr = top; top = new_top; size++; }; public static void popO { if(top == null){ System.out.println("Stack is empty");