Stack Implementation - Array

Поділитися
Вставка
  • Опубліковано 18 вер 2024

КОМЕНТАРІ • 13

  • @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_ Рік тому

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

    • @BlueTreeCode
      @BlueTreeCode  6 місяців тому

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

  • @sunnylin8587
    @sunnylin8587 3 роки тому

    Thanks a lot 😊

  • @JakubMazur-v5s
    @JakubMazur-v5s 6 місяців тому

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

  • @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 :)

  • @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 :)

  • @radhaiahb3212
    @radhaiahb3212 4 роки тому

    Please cover data structures please

  • @radhaiahb3212
    @radhaiahb3212 4 роки тому

    Can u explain abstract classes-polymorphism from hackerrank

    • @BlueTreeCode
      @BlueTreeCode  3 роки тому

      I can probably do a video on OOP later on.