| about | help | code help+videos | done | prefs |
tmhscs@gmail.com stacks
Stacks are a simple data structure where you can only modify the top element. This makes stacks a FILO (first-in-last-out) or LIFO (last-in-first-out) structure. Here are some of the methods that you will need to use and master:
Stack<TYPE> stack = new Stack<TYPE>(); // creates an empty stack // TYPE should be replaced with a class name, like Integer or Stringstack.push(VALUE); // pushes a value onto the top of the stack stack.peek(); // returns the element on the top of the stack stack.pop(); // removes AND returns the element on the top of the stack stack.size(); // returns the number of elements in this stack stack.clear(); // removes all values from this stack stack.isEmpty(); // returns true or false if the stack has no elements in it int pos = stack.search(VALUE); // returns the 1-based position of the value in the stack // Search: If it returns 1, that means it is on top. If it returns -1, it isn't in the stack
NOTE, CODINGBAT DOES NOT COMPLETELY SUPPORT STACKS
ON MANY QUESTIONS YOU WILL HAVE TO DO THE FOLLOWING:
START PROBLEM WITH:
Stack<Integer> stack = new Stack<Integer>();
stack.addAll(list);
IF PROBLEM HAS ARRAYLIST AS RETURN VALUE, END PROBLEM WITH:
return new ArrayList<Integer>(stack);
Easy Problems:
01.
stack_makeStack H stack_makeStack
02.
stack_numberOfElements H stack_numberOfElements
03.
stack_peekStack H stack_peekStack
04.
stack_popStack H stack_popStack
05.
stack_secondElement H stack_secondElement
06.
stack_searchStack H stack_searchStack
07.
stack_searchAndPushIndex H stack_searchAndPushIndex
08.
stackHead7 stackHead7
09.
stackHead7b stackHead7b
10.
stackHeadNot3 stackHeadNot3
11.
stackHeadNot3b stackHeadNot3b
12.
stackHeadPlus8 stackHeadPlus8
13.
stackHeadPlus8b stackHeadPlus8b
Medium Problems:
14.
stacks_pushIt H stacks_pushIt
15.
stackTail7 stackTail7
16.
stackAdd1 stackAdd1
17.
sumStack sumStack
18.
sumStackAdd sumStackAdd
19.
stackRemove4 stackRemove4
20.
stackMin stackMin
Hard Problems:
21.
isSorted isSorted
22.
balanceBrackets balanceBrackets video tutorial: https://youtu.be/CCyEXcNamC4?t=87
Authoring docs
Copyright Nick Parlante 2017 - privacy