02 Stack, queue, prepoin
- gardionsaltana
- Mar 2, 2020
- 3 min read
First we're going to explain about stack concept
Stack is like stacking a box, you cannot move the bottom box, but you must move the top one first.
By using this concept we can see the last thing we put, the thing we put will be put in the last place.
Command:
Push() = We're pushing aka put some box on top of the heights box.
Pop() = We're poping like smack the rat minigame, we're see the last data we put in.
Clear() = To pull the most bottom box aka delete the stack.
IsEmpty() = To check whether there any box left or not.
IsFull() = To check has the box reach the celling.
Queue concept
Like waiting in a line for your new iPhone, the concept is the same first in first out simple right? Reminder if you set the size to 10, you cannot over it like array. once you define it you cannot put more of the data. What make this thing unique is because if you use dequeue the data will not size 10 but size 9 because the head(first data) you move it upward to the second data. And the only way to make it 10 again you must reset the program.
Command:
enqueue() = To store data aka put somebody in the line.
dequeue() = Kick the first person in line.
peek() = Imagine your at the back of the line what do you do when the word peek pop up.. see the first idiot who sleep in the street waiting for the new iphone.
isfull() = Check if the line full or not.
isempty() = When nobody waiting in line for the new iphone you better check what's going on.
Circular queue basicly the same but now box are place to made a circle rather than you stack upon the and in the end you will meet the first get it no? oke just imagine a monopoly board except this time you only can move one step at a time.. What make it diffrent from normal queue aka linear queue, because if you use dequeue the size will still be 10 why? Because it goes around, let see the example in monopoly everystep you move creates a hotel, if you delete the first hotel. One way or another you will step again in the first hotel and you can create the hotel again. So the size will still be 10.
Infix, Prefix, Postfix
- Infix
The basic of math.
...
If you read this and knows how to operate a calculator that means you have understand Infix.
- Prefix
The command like * | + |- | / runs first (* is multiply btw)
example
5 + 6
= + 5 6
How do you read it?(easy method for me)
Start from the right until you find two numbers at the most left and next to it is a command.
example
* 5 * 5 + 3 5
3 5 is the right side number
next to it is + sign
so 3 + 5 = 8
move on the next number is 5
5 * 8 = 40
and the final answer is 40 * 5 = 200
Btw () | {} is useless
- Postfix
The number show up first
The tactic is the same with prefix but now you read it from the left ez right?
example
3 9 4 * + 7 +
9 and 4 is the number
9 * 4 = 36
36 + 3 = 39
39 + 7 = 46
Ez right? no... well goodluck
Here 's an example
(1 + 3) / (100 * 5) ^ 30
How to make it to prefix and postfix
prefix
see all the command and make it to prefix
+ 1 3 / * 100 5 ^ 30
/ + 1 3 * 100 5 ^ 30
^ / + 1 3 * 100 5 30
Hard? How about like this
+ (1 3) / * (100 5) ^ 30
/(+ (1 3) * (100 5)) ^ 30
^(/(+ (1 3) * (100 5))) 30
^ / + 1 3 * 100 5 30
Did you get it? Just put to command next to left number
Postfix is the opposite, do it on your own.
The answer for postfix is 1 3 + 5 100 * / 30 ^

Comments