You could also start with top = -1, that way way your indices look nice and in sync with top, so for peek you will return stack[top] instead of stack[top -1]
@@nemanja6290 The position of top is incremented every time an element is pushed. So for the first push, top will become 0 (in sync with the stack array)
Excellent,your discussion is always deep,informative,right and easy to understand..anything listening from you is a learning..please keep on this job in faster way.Implementation of data structures and algorithmic design principles in java is more important as it's relatively easy.So we expect eagerly the total series videos in much more faster way...many many thanks to you...
push(12), push(4), push(8) --->>> (with your show() method) --->>> 12, 4, 8 but it should be 8, 4, 12. Last in first out. But anyway good video, maybe your goal was something different.
@@surentheranvenkatesan6290 I have given enough memory so that stack shouldn't get overflowed If we use list in place of array memory will not be wasted
Thank you very much for explaining this while making it. My teacher gave us code to download and only to create the main. This made me understand everything, keep it up man.
Yes.When u push 2 valuse into stack then the top is 1(0,1).Now the top values is at the postion or index at 1.when u pop an element from stack it will decrement by 1(top--;)
Wonderful explanation but I am reading from a book, I am unable to understand stack code in the reference book of Java 7th edition, can you please help me with it ?
This is sorting arrays, not handling the stack, if you mean the java Collection class Stack, sir. Push put automatically on top and pop automaticly drops the top layer from the stack.
In this example, after adding some values, remaining value are 0 that we are not suppose to do. If we add 0 then it will make confusion. It is also not showing in implemented Stack in java.
@@gabrieldenobrega Could you explain how you would do that in code? I have looked up what wrapper classes are but I cannot see how it would benefit here.
@@LynnyrdRavage Hello, Ernesto! Nice to meet you and I'm sorry I took so long to answer you. So, what I wanted to say in my original commentary is that by using "Wrapper Classes" you can fill and array with null values, which means you don't have to worry about having actual values in the array. In case you had doubts about what "Wrapper Classes" are (which seems you did), I'll quickly explain to you what they are: "Wrapper Classes" are much alike primitive types in Java, but they have the advantage of allowing the use of the primitive types along with the advantages of OOP. To use a "Wrapper Class" you simply declare the type of the variable with a capital letter instead of writing it the regular way. For example, for a double value you're not going to code "double varName", you're gonna code it as "Double varName". That way you're gonna be able to have a null value stored in it and you're also going to be able to use some methods that the "Wrapper Classes" provide us with. I really hope that my answer helps you out, hugs!
Hi sir, I can't able to understand your "InterThread Communication" program on multithreading concept. You can find that video on your java playlist. Can you please make a video to explain that program step by step.??? Waiting for your reply
Overflow means suppose the stack is of array size 10. Now consider a situation when all 10 elements(that may be integer number or double or whatever) are filled . So now if you push 1 more element , then as there is no extra space , so we say this condition as Stack overflow . And if you consider the reverse situation . Suppose your stack is completely empty . Now if you use pop operation , it has nothing to pop right!!! This situation is called stack underflow :-)
import java.util.Scanner; class Stack { private int[] stackArray; private int top; // Constructor to initialize the stack with a fixed size public Stack(int size) { stackArray = new int[size]; top = -1; // Indicates stack is empty } // Push an element onto the stack public void push(int value) { if (top == stackArray.length - 1) { System.out.println("Stack Overflow! " + value); } else { stackArray[++top] = value; System.out.println("Pushed " + value); } } // Pop an element from the stack public void pop() { if (top == -1) { System.out.println("Stack Underflow! Stack is empty."); } else { System.out.println("Popped " + stackArray[top--]); } } // Display all elements in the stack public void display() { if (top == -1) { System.out.println("Stack is empty."); } else { System.out.print("Stack elements: "); for (int i = 0; i
First thanks for the video, it was so helpful. i try to get input form the user to decide the size of the array, but for some reason it will show me runtime error, can someone help me pls public class Stack { // public int a ; public int[] stack = new int[a]; int top = 0; public void push(int data) { stack[top] = data; top++; } public void pop() { if (top
May be this is the most simplified and effective illustration of stack on any java compiler in the whole TH-cam! Thanks for this great contribution
keep going, we are 40 Computer Science students most of us just watching your videos
on the same phone ?
@@parikshitrajpara5706 recommend by the lecturer
how did computer science went for you?
@@wesibrani7561 thats true bro thanks
You could also start with top = -1, that way way your indices look nice and in sync with top, so for peek you will return stack[top] instead of stack[top -1]
Hey biginner here, if he puts top = -1, then the first value in the array is gonna be -1?
@@nemanja6290 The position of top is incremented every time an element is pushed. So for the first push, top will become 0 (in sync with the stack array)
@@PriyanshuShukla7 but at the end of the array it will go out of bounds
System.out.println(" great explanation");
thank you
Very easy to understand, exactly what I needed to know to help with an assignment. Thank you very much!
Hello Aliens!😂
The most helpful video I have ever watched about Stack. Thanks
Great video - straight to the point, fast, informative.
Sir I have really amazed in u r videos teaching method impresive.I see in many videos java stack this explain clear so good sir
I am currently stuck in java and this video helped tremendously!
Thanks for the video, very helpful
awesom guy! best explanation in the whole YT fr fr
it is a valuable video for us to understanding the concept very easily.
this is most easier video i have ever seen sir tnx a lot
A huge thankss to you sir. This is the first very part in DSA which I have understood fully.
Excellent,your discussion is always deep,informative,right and easy to understand..anything listening from you is a learning..please keep on this job in faster way.Implementation of data structures and algorithmic design principles in java is more important as it's relatively easy.So we expect eagerly the total series videos in much more faster way...many many thanks to you...
push(12), push(4), push(8) --->>> (with your show() method) --->>> 12, 4, 8 but it should be 8, 4, 12. Last in first out. But anyway good video, maybe your goal was something different.
my implementation: 👇👇
import java.util.*;
public class stackMainMeathod{
public static void main(String[] args) {
stack num=new stack();
num.push(88);
num.push(79);
num.push(3);
num.push(673);
num.push(38);
System.out.println(num.pop());
num.push(896);
System.out.println(num.isEmpty());
System.out.println(num.peek());
num.show();
}
}
class stack{
int arr[]=new int[100];
int top=-1;
public void push(int element){
top++;
arr[top]=element;
}
public int pop(){
int temp=arr[top];
arr[top]=0;
top--;
return temp;
}
public boolean isEmpty(){
if(top==-1)
return true;
else
return false;
}
public void show(){
for(int i=0;i
Why you use arr=100; waste of memory;
@@surentheranvenkatesan6290 I have given enough memory so that stack shouldn't get overflowed
If we use list in place of array memory will not be wasted
@@random-0 than I think no reason to use Stack
@@mindgym4543 what?
At peek if u return arr[top], its 0 nah?
Bcs at pop u assigned 0 for arr[top]
Thank you very much for explaining this while making it. My teacher gave us code to download and only to create the main. This made me understand everything, keep it up man.
thanks a lot sir u have cleared my test about linkedlist,stack,and quee,
Then what is difference between insert at start and push
A crystal clear exaplanation!
Nice explanation thankyou 🙏🏼
This is a simple and very effective video of Stack implementation by array. Upload more such useful content Sir
Finally someone talked sense!
Thank you!!!! data structures exam in 14 hours LOL
Good Explanation Sir...😊
8:37 why did we do [top-1] ?
I loved the way you explained it, thanks a lot.
At the beginning try assigning top=-1;
All the operations after that will be clear.
Very informative and clear explanation.Hope you'll keep doing this service
Extraordinary explanation..
Great video very clear and informative. Thanks
you are simply great sir, what an explaination!!!!!!!!!!!
finally I learned data structures tq guruji
Good job Sir for Giving crystal clear concept
Great explanation
Really helpful but you should have completed the full playlist i.e tree & graph
Sir shall i use vector for stack please tell me
Thank you for the great explanation it was very useful to me :)
So to read each element of the stack, a simple for loop would solve it?
in the pop method, does top-- will be decremented like 4, 3, 2, 1, 0 right?
Yes.When u push 2 valuse into stack then the top is 1(0,1).Now the top values is at the postion or index at 1.when u pop an element from stack it will decrement by 1(top--;)
Can I make these methods without an array?
the .show() method doesnt seem to work properly anymore. What has it been replaced with?
Thank you Sir, I easily understood Stack.
May I know why in peek method, why we need to take top - 1 but not top? thank you
Because in push we have incremented top, so to get the actual top shown we need to decrement ist. At least that's how I understand it.
can you please make a video explaining a program about infix, postfix and prefix expression in stack
Great explanation!
Wonderful explanation but I am reading from a book, I am unable to understand stack code in the reference book of Java 7th edition, can you please help me with it ?
Thank you so much, you have explained this perfectly
THANKS IT JUST CLEARED MY CONCEPTS :)
I don't understand why are we doing our own implementation when we have inbuilt classes...There has to be some limitations in inbuilt ones!
this is simplest explanation i have seen till now
why are we doing data = stack[top-1] instead of just writing data = stack[top] in peek operation
Is that an app that you are using on the left side?
Ya that's eclipse
@Telusko Learnings
sir can u pls demonstrate how to implement stack using linked list
Thanks @telusko🤗
This is sorting arrays, not handling the stack, if you mean the java Collection class Stack, sir.
Push put automatically on top and pop automaticly drops the top layer from the stack.
In this example, after adding some values, remaining value are 0 that we are not suppose to do. If we add 0 then it will make confusion. It is also not showing in implemented Stack in java.
To avoid this problem you should use wrapper classes to create the array. That way you'll have it filled with null values instead of zeros.
@@gabrieldenobrega Could you explain how you would do that in code? I have looked up what wrapper classes are but I cannot see how it would benefit here.
@@LynnyrdRavage Hello, Ernesto! Nice to meet you and I'm sorry I took so long to answer you. So, what I wanted to say in my original commentary is that by using "Wrapper Classes" you can fill and array with null values, which means you don't have to worry about having actual values in the array. In case you had doubts about what "Wrapper Classes" are (which seems you did), I'll quickly explain to you what they are: "Wrapper Classes" are much alike primitive types in Java, but they have the advantage of allowing the use of the primitive types along with the advantages of OOP. To use a "Wrapper Class" you simply declare the type of the variable with a capital letter instead of writing it the regular way. For example, for a double value you're not going to code "double varName", you're gonna code it as "Double varName". That way you're gonna be able to have a null value stored in it and you're also going to be able to use some methods that the "Wrapper Classes" provide us with. I really hope that my answer helps you out, hugs!
Please provide the link for the source code.
Hi sir, I can't able to understand your "InterThread Communication" program on multithreading concept. You can find that video on your java playlist. Can you please make a video to explain that program step by step.??? Waiting for your reply
great work, nice explanation!
Great video thanks please make more java tutorial.
very useful
7: 52 Decrement top before using? Can anyone explain?
because in previous action of push after pushing the elemnt we did top++ so it was pointing to 0 on index 3 so in pop we needed to do top--
very goog explain sir
can anybody explain why we are using top-- in pop method ?
how we can remove the zero?
Sir...can you make video on implementation of stack using linked list..
How to implement the same code with Node and linkedlist
i have one doubt pop section can you explain it
please give details about overflow and underflow condition in stack
Overflow means suppose the stack is of array size 10. Now consider a situation when all 10 elements(that may be integer number or double or whatever) are filled . So now if you push 1 more element , then as there is no extra space , so we say this condition as Stack overflow . And if you consider the reverse situation . Suppose your stack is completely empty . Now if you use pop operation , it has nothing to pop right!!! This situation is called stack underflow :-)
Sir,Could you give me some guide lines to learn data structures with theory and practical from your videos ,Could you tell me playlists to follow
Please Sir add more Videos For data Structures whole course please
you are good , keep it up.....
Good for beginners!
superb video.
why can't we use only one class to implement full stack ???
very good and detail
THANK YOU SO MUCH
Make videos on swift tutorials
bm - 4:51
why there is [top-1] in peek method
Here the top is at the index of 2.when u use top-1(2-1=1)and the index of 1 is 8.
Subscribed
Why are you working from two different java files and not just one?
As this is object oriented programming , so helping class is written in 1 file & main class is written in another one :-)
why top-1 for peek?
Because every time we push we increment the value of top as well, therefore, it needs to be decreased before using pop or peek
Yeah..why top -1 for peek ??...a bit confused
suppose I inserted value at stack[0], now top++ therefore now top=1, so to show my top value I have to decrement top by -1
Please refer the code to understand my explanation.
while(true) 👌👌🔥
where is the upcoming video
import java.util.Scanner;
class Stack {
private int[] stackArray;
private int top;
// Constructor to initialize the stack with a fixed size
public Stack(int size) {
stackArray = new int[size];
top = -1; // Indicates stack is empty
}
// Push an element onto the stack
public void push(int value) {
if (top == stackArray.length - 1) {
System.out.println("Stack Overflow! " + value);
} else {
stackArray[++top] = value;
System.out.println("Pushed " + value);
}
}
// Pop an element from the stack
public void pop() {
if (top == -1) {
System.out.println("Stack Underflow! Stack is empty.");
} else {
System.out.println("Popped " + stackArray[top--]);
}
}
// Display all elements in the stack
public void display() {
if (top == -1) {
System.out.println("Stack is empty.");
} else {
System.out.print("Stack elements: ");
for (int i = 0; i
Without using pop method to print the popped element it will print 0 by default
Thanks alot.
What happened to screen
First thanks for the video, it was so helpful. i try to get input form the user to decide the size of the array, but for some reason it will show me runtime error, can someone help me pls
public class Stack { //
public int a ;
public int[] stack = new int[a];
int top = 0;
public void push(int data) {
stack[top] = data;
top++;
}
public void pop() {
if (top
provide sourcecode
can i ask something
No
thanks
Why aliens?
Pier disapproves >:(
System.out.println("nice")
you forgot the comma to end your line xD
system.out.println("nice");
that's better haha :)
cout
too fast
Stack in java is the title.. And it accepts integers only.. Very low level thinking.. Nothing on access modifiers too..
Tusi kukad kho hooooooooo