Data Structures and Algorithms – Summer 2019 – Test A
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
public class MyDynamicStack { private int stackSize; private int[] stackArr; private int top; /** * constructor to create stack with size * @param size */ public MyDynamicStack(int size) { this.stackSize = size; this.stackArr = new int[stackSize]; this.top = -1; } /** * This method adds new entry to the top * of the stack * @param entry * @throws Exception */ public void push(int entry){ if(this.isStackFull()){ System.out.println(("Stack is full. Increasing the capacity.")); this.increaseStackCapacity(); } System.out.println("Adding: "+entry); this.stackArr[++top] = entry; } /** * This method removes an entry from the * top of the stack. * @return * @throws Exception */ public int pop() throws Exception { if(this.isStackEmpty()){ throw new Exception("Stack is empty. Can not remove element."); } int entry = this.stackArr[top--]; System.out.println("Removed entry: "+entry); return entry; } /** * This method returns top of the stack * without removing it. * @return */ public long peek() { return stackArr[top]; } private void increaseStackCapacity(){ int[] newStack = new int[this.stackSize*2]; for(int i=0;i<stackSize;i++){ newStack[i] = this.stackArr[i]; } this.stackArr = newStack; this.stackSize = this.stackSize*2; } /** * This method returns true if the stack is * empty * @return */ public boolean isStackEmpty() { return (top == -1); } /** * This method returns true if the stack is full * @return */ public boolean isStackFull() { return (top == stackSize - 1); } public static void main(String[] args) { MyDynamicStack stack = new MyDynamicStack(2); for(int i=1;i<10;i++){ stack.push(i); } for(int i=1;i<4;i++){ try { stack.pop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
Kindly revert for any queries
Thanks.
Data Structures and Algorithms – Summer 2019 – Test A Code an array implementation of a...
Data Structures and Algorithms – Summer 2019 – Test A In the linked list implementation of a Queue, there are two distinct structures that can represent an empty Queue. Draw a diagram of each and explain why both would be considered to be an empty Queue.
Data Structures and Algorithms. (C++ Language) 1. Write the definition code for a function that passes in a stack and returns (using a return statement) the number of items in the stack (the stack size). a. assume the this function is to be toolkit function in the implementation of the ADT stack. b. assume that this function is not a toolkit function. 2. Given the declaration: s = stack i = item struct STACK { INFO_RC i; int top; }...
Summer II 2020 - Data Structures and Algorithms (COSC-2336-01W) In the linked-list based bag implementation, we demonstrated the functionalities, such as, add, remove, and list. This assignment is to extend the functionalities of the bag with other operations average, min, and max, You need to extend the Bag class (under Wk 2, BagLinked_List.cpp) with the following methods: -int Bag::min( ), is to find minimum of items of the bag. -int Bag::max( ), is to find maximum of items of the...
C++ Data structures and Algorithms Use a Queue to reverse a stack in place. Assume you are given a stack of string values like Stack s; using a Queue, cause all of the items in the stack to be reversed. For example, if you have the following contents on the stack s Top --- bird cat dog turtle ----- Bottom After you run your code, you stack contents should look like Top --- turtle dog cat bird ----- Bottom
---Using Java to solve--- Write the code for three sort algorithms. Sort an array of Integers, strings and an array of Cars using each technique. At least seven items in each case.
Student Name Student ID CS209 Data Structures and Algorithms - Quiz 1/2e Friday, Feb 22, 2019 1. (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Bubble sort (sorting smallest to largest). (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Selection sort (sortin from smallest to largest)....
In this assignment you will practice using Data Structures and Object Oriented concepts in Java. Your implementation should target the most efficient algorithms and data structures. You will be graded based on the efficiency of your implementation. You will not be awarded any points if you use simple nested loops to implement the below tasks. You should use one or more of the below data structures: - ArrayList : - JavaDoc: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html - Tutorial: http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html Question You are provided with...
Software Data Structure & Algorithms 1- Write a java method that reversing an array using a stack. Use ArrayStack(). 2- Write a java method that implement matching delimiters. Use LinkedStack.
Data Structures and Algorithms Help please :) POLJOPP 3. Consider QuickSort on the array Aſlanand assume that the pivot element x (used to split the array Allo:hil into two portions such that all elements in the left portion Allom) are sx and all elements in the right portion Aſm:hi) are >x) is the last element of the array to be split (i. e., A[hi]). For a specific value of n at least 11 (your choice), construct an assignment of the...
q: Write a java code to Test the heap sort algorithm Test the algorithms on arrays of size: .100,000 , 90,000 ,80,000 ,70,000 ,60,000 ,50,000 ,40,000 ,30,000 ,20,000 ,10,000 Plot the execution time vs array size. without using excel