Stack Implementation - Array

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

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

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

    Hey Everyone! Thanks for checking out my video! Don't forget to Like, Subscribe, and MOST IMPORTANTLY click that Notification Bell for updates! :)

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

    That’s the best explanation video I’ve seen so far, thank you so much!

    • @BlueTreeCode
      @BlueTreeCode  9 หลายเดือนก่อน

      Thanks a lot!! Please don't forget to like and share as it will help the channel grow.

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

    Kevin, do you know how to make interface files for LinkedList, Stack and Queue with all-around functionalities?

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

      Hi Eoghan, yep.
      Here's an example:
      Let's suppose you wanted to use the Stack functionality in a LinkedList, then you can do
      something like the following.
      NB: I'm assuming that you may want to store other data types and not just integers. In that case, I'll throw in some
      generics.
      public interface Stack {
      void push ();
      T pop() throws NoSuchElementException; // (in our case, also don't forget to import java.util.NoSuchElementException)
      T peek() throws NoSuchElementException; // (in our case)
      boolean isFull();
      boolean isEmpty();
      void resize();
      }
      You can then " implement " our Stack interface in a LinkedList class you're building.
      public class LinkedList implements Stack {
      private T head;
      public LinkedList(T head){
      this.head = head
      }
      @Override
      public void push(T value){
      .....
      }
      @Override
      public T pop throws NoSuchElementException{
      ....
      }
      ..... And so on
      }
      You can also build a Queue interface and have the same LinkedList class extend it as well, achieving both Stack and Queue functionalities:
      E.g) public Class LinkedList implements Stack, Queue { ... }
      Once you've done that, you can use the LinkedList like this:
      class Driver {
      LinkedList someLL = new LinkedList(null);
      }
      Hope this helps :)

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

    May I ask why three instance variables are using private and the Push method using ++top(because you want top immediately increase by 1?)

    • @BlueTreeCode
      @BlueTreeCode  4 ปีที่แล้ว +3

      Hi Alex Yip, private variables introduce 'Encapsulation' to the class. It's simply a precautionary measure so that classes outside of it can't access and manipulate those variables. You can remove the 'private' modifier if you wish to.
      As for ++top, you are absolutely correct. ++top is so that the value of top is increased before assigning 'data' to it. If we used top++, we would end up replacing the value at the top of the stack and then adding one to top.
      Hope this helps :)

  • @jakmazdev
    @jakmazdev 9 หลายเดือนก่อน

    Isn't top variable obsolete? The top will be always size-1

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

    Thanks a lot 😊

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

    Can u explain abstract classes-polymorphism from hackerrank

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

      I can probably do a video on OOP later on.

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

    Please cover data structures please