#11 Stack Implementation using Java Part 2 | Size and isEmpty Methods

preview_player
Показать описание

Stack implementation in Java without using Collection.

In this video we will see practical implementation of Stack without using Collection in Java

We will see :
- Stack Operations :
- Push
- Pop
- Size
- isEmpty

Stack : It is Last-In-First-Out (LIFO) DS
The name "stack" for this type of structure comes from the analogy to a set of physical items stacked on top of each other, which makes it easy to take an item off the top of the stack,
while getting to an item deeper in the stack may require taking off multiple other items first
We can perform 2 operation on it :
PUSH : which adds an element to the collection, and
POP : which removes the most recently added element that was not yet removed

Editing Monitors :

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

Really sir I like ur videos...coz ur teaching method is best..keep it up and make more videos for us..

PlayNinja
Автор

Thanks for this wonderful video. May gbu with lots of success love and life. Keep Rocking
Bhai DSA Pura kardo please..ALL VIDEOS ARE GREAT

travelnlearn
Автор

Finally I found my online programming tutor

kanchapaudukumbura
Автор

Amazing idea and explanation again thanks

iftak
Автор

Sir please make video on....
What is prerequisites for making an

pavankalyanpanga
Автор

Please make a video on algorithms and data structure using Java sir!

surojitdas
Автор

really thank you for helping us, your way to writing the code is really sexy and its amazing.
thank you brother <3

ezelpayrktar
Автор

The top has to be top=top-1 before performing seek or pop??
because if we are inserting any value with that value the top is also increased.
plz tell????

amitbudhiraja
Автор

this lectures are saving me, tnx!
by the way, cant isEmpty be like this

public boolean isEmpty() {
return top == 0;
}

or

public boolean isEmpty() {
return zise() == 0;
}

why the < symbol ? even tho it works still

josephjoy
Автор

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.???

DineshKumar-tidx
Автор

why add 0 while pop ? adding 0 is not deletion and 0 is also a value. Not convinced.

yogeez
Автор

import java.lang.reflect.Array;

public class GenericStack<T>{
private T[] array;
private int top=0;

public GenericStack(Class<T> clazz, int capacity){
array = (T[])Array.newInstance(clazz, capacity);
}

public void show(){
for(T element:array){
System.out.print(element+" ");
}
System.out.println();
}

public void push(T data){
if(top==array.length){
System.out.println("stack is full !!!");
return;
}

array[top] = data;
top++;
show();
}

public T peek(){
if(isEmpty()){
System.out.println("Stack is empty !!!");
return null;
}
System.out.println("last element:->"+array[top-1]);
return array[top-1];
}

public T pop(){
if(isEmpty()){
System.out.println("Stack is empty !!!");
return null;
}
top--;
T data = array[top];
array[top]=null;
show();
return data;
}

public boolean isEmpty(){

return top<=0;
}

public int size(){
System.out.println("stack size is:"+top);
return top;
}
}

himanshubansal
Автор

sir if the stack is full and still I want to add more values in above case, after getting stack is full message instead of it I want to add more elements, so how we can do this?-for this problem we have to create one more array but how we can maintain previously added values.?

prateshtamhankar
Автор

sir..in size(), top variable was supposed to be decremented by one, as in push() it was incremented by one each time push() called....isn't that???

saadmanahmed