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

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

ความคิดเห็น • 27

  • @SarbashisPaul
    @SarbashisPaul 3 วันที่ผ่านมา

    @Telusko thank you so much for your contribution.

  • @PlayNinja72
    @PlayNinja72 4 ปีที่แล้ว +2

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

  • @kanchapaudukumbura7991
    @kanchapaudukumbura7991 4 ปีที่แล้ว +2

    Finally I found my online programming tutor

  • @msRama-sz7bh
    @msRama-sz7bh 5 ปีที่แล้ว +11

    should've initialized Top =-1;

  • @pavankalyanpanga1056
    @pavankalyanpanga1056 6 ปีที่แล้ว +1

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

  • @travelnlearn
    @travelnlearn 3 ปีที่แล้ว +1

    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

  • @surojitdas7139
    @surojitdas7139 3 ปีที่แล้ว

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

  • @ayushbudhwani
    @ayushbudhwani 4 ปีที่แล้ว

    Loved it. From USA

  • @josephjoy7080
    @josephjoy7080 3 ปีที่แล้ว

    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

  • @iftak01
    @iftak01 4 ปีที่แล้ว +1

    Amazing idea and explanation again thanks

  • @amitbudhiraja4135
    @amitbudhiraja4135 4 ปีที่แล้ว +1

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

  • @himanshubansal6425
    @himanshubansal6425 5 ปีที่แล้ว +2

    import java.lang.reflect.Array;
    public class GenericStack{
    private T[] array;
    private int top=0;

    public GenericStack(Class 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(){
    System.out.println("Empty:-->>"+(top

  • @yogeez123
    @yogeez123 6 ปีที่แล้ว +3

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

    • @richardmaduka4747
      @richardmaduka4747 6 ปีที่แล้ว

      In Java, int fields(class level variables) values are automatically initialized to 0 by default. Therefore reverting the value in the index back to 0 is setting it to its default value. Int is a primitive data type and cannot be null.

    • @newtonsarr1234
      @newtonsarr1234 5 ปีที่แล้ว +1

      ​@@richardmaduka4747 Yes but Aswin has a point. if 0 is one of the actual integer values stored in the stack then how would you differentiate ?
      A stack is only delimited by the index of the top, not by the values in the array (whether they are 0 or not). Even if you stored values other than zero, someone will know where the stack starts and stops in the array as long we maintain a pointer to the top. If you know the top, then you know where your stack stops, it does not matter if the indices out of the stack contain zero or non zero elements. Putting 0 is actually misunderstanding what stacks are.

    • @lopitalisa
      @lopitalisa 4 ปีที่แล้ว

      adding 0 will probably be because he used a primitive type int, if a generic type or an object were used, then null would have been a good option.

  • @DineshKumar-ti1dx
    @DineshKumar-ti1dx 6 ปีที่แล้ว

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

  • @ezelpayrktar7381
    @ezelpayrktar7381 5 ปีที่แล้ว +3

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

  • @gazisharinmostafiz
    @gazisharinmostafiz 5 ปีที่แล้ว

    best teacher

  • @prateshtamhankar3568
    @prateshtamhankar3568 6 ปีที่แล้ว

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

    • @acheng4853
      @acheng4853 6 ปีที่แล้ว +2

      Instead of using an array where you can't add when the stack is full, use a dynamic array, aka ArrayList (I think #12 in the playlist shows implementation of stacks using ArrayList)

    • @newtonsarr1234
      @newtonsarr1234 5 ปีที่แล้ว +1

      You can also implement a stack data structure using a LinkedList if you are worried about array size. Else you use a dynamic array or ArrayList

  • @kolakalurisukeerth358
    @kolakalurisukeerth358 4 ปีที่แล้ว

    Baaga Telusukuna Sir :P

  • @bipkromo
    @bipkromo 6 ปีที่แล้ว

    can we get the code ?

  • @saadmanahmed860
    @saadmanahmed860 6 ปีที่แล้ว

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

    • @ibakshay
      @ibakshay 6 ปีที่แล้ว

      size is starting from 1 rather than 0. thats why he left it as such