Data Structures: Linked List implementation of stacks

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024
  • See complete series on data structures here:
    • Data structures
    In this lesson, we have discussed linked list based implementation of stack data structure.
    For practice problems and more, visit: www.mycodeschoo...
    Like us on Facebook: / mycodeschool
    Follow us on twitter: / mycodeschool

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

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

    7 year's ago he explained ,but still the best explanation

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

      this channel is evergreen

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

      true

    • @cp65143
      @cp65143 9 หลายเดือนก่อน +1

      10 yrs ago

  • @ChienChiWang
    @ChienChiWang 9 ปีที่แล้ว +87

    I'm Taiwanese and thank you for making this video!!
    Your videos not only CLEAR but HAVE SUBTITLES!
    It's very helpful for those native language are not English.

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

      taiwan belongs to china so u r chinese

    • @mehularora3234
      @mehularora3234 4 ปีที่แล้ว +19

      @@zackdon264 No Taiwan is Independent from China . Do not hurt their soverignity .

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

      @@mehularora3234  u r a idiot

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

      @@zackdon264 but he is not xi ping ping

    • @AmanKumar-nj5sz
      @AmanKumar-nj5sz 3 ปีที่แล้ว +1

      @@zackdon264 U look more like one

  • @mycodeschool
    @mycodeschool  11 ปีที่แล้ว +45

    Thanks Micheal !! We are working hard to get all the videos for you. :)

  • @m.mubashar786
    @m.mubashar786 3 ปีที่แล้ว +23

    A man telling the definition of linked list and explaining it in detail even he taught in his previous lectures......Superb Bro!!!

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

      western education is haram....stop coding, spread islam

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

      ​@@maitahom9958show me the proof of your word and tell me does your religion taught you to behave like this?

    • @yousof8546
      @yousof8546 11 หลายเดือนก่อน

      no hes just ignorant@@muhammadfurqanalam

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

    After wasting 2 weeks I finally found a data structures playlist which I needed, LinkedIn Learning, Pluralsight everything failed but TH-cam saved me. Thank you!

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

    Finally here....After watching countless YT channels and visiting countless websites .... Finally this is the best explanation that I have ever found...❤️

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

    this course is 9 years old still the best explanation topic wise and time saving as well as easy to understand.

  • @WonderingSoccer
    @WonderingSoccer 9 ปีที่แล้ว +10

    Hi Bro, you make the stack of Linked List very clear and straightforward, like it very much, and I enjoy your accent a lot! Keep up to it!

  • @jcpfmc
    @jcpfmc 5 ปีที่แล้ว +4

    Thank you so much for your tutorials, they are so clear and visual which helps me understand the concepts!

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

    i just saw your stack implementation with Arrays, made my day!

  • @tomasz-rozanski
    @tomasz-rozanski 7 ปีที่แล้ว +12

    You can also reuse IsEmpty() function inside the Pop() function, so instead of:
    if (top == NULL)
    you could write
    if (IsEmpty())

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

      nice solution

    • @VijayPatil-qj7xd
      @VijayPatil-qj7xd 6 ปีที่แล้ว +1

      In point of reusability and maintainable its good to have IsEmty call, but will degrade performance of code since it’s additional function call. Correct me if needed.

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

      Depends on the language and compiler, a function that simple/short is likely to be inline. If not, you're correct, we'll have the cost of the stack frame allocation, etc.

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

    10 years ago, Really better explanation than 2 hour lecture

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

    Such clarity! This is the answer to our midterms in Data Struct last time. How I wished I watched this video earlier. TT ~TT

  • @Rajyalakshmi958
    @Rajyalakshmi958 4 หลายเดือนก่อน

    He explained 10years ago still no one can beat him

  • @gauravdotiyal7171
    @gauravdotiyal7171 ปีที่แล้ว

    the best explanation of topics in youtube🙌🙌

  • @ofir332
    @ofir332 8 ปีที่แล้ว

    Much more clear than my professor (and eng is not my first language)
    you sir, teach very well and know your job

  • @bhumipatel9617
    @bhumipatel9617 9 ปีที่แล้ว +22

    i hope u will make this type of video again n again.

  • @spikeguy33
    @spikeguy33 10 ปีที่แล้ว +17

    Really helpful and well made video. Also, cool accent, reminds me of my Finnish friend :)

    • @kyssl
      @kyssl 7 ปีที่แล้ว +4

      UrbanTarzan Duh It's an Indian accent btw..

  • @akashdubey.consultant
    @akashdubey.consultant 8 ปีที่แล้ว +2

    wonderful explanation, btw on 07:36 you got to correct sizeof to be just sizeof(struct Node)) , please note it may get compiled but you won't be able to loop and print values, i just figured it when i ran into the problem

  • @MaNgOsEr85
    @MaNgOsEr85 9 ปีที่แล้ว +18

    Here is my complete code with a switch function to use it properly :)
    Btw, thank you so much mycodeschool !
    #include
    #include
    struct Node {
    int data;
    struct Node* link;
    };
    struct Node* top = NULL;
    void Push(int x) {
    struct Node* temp = (struct Node*)malloc(sizeof( struct Node*));
    temp->data = x;
    temp->link = top;
    top = temp;
    }
    void Pop(){
    struct Node *temp;
    if(top == NULL) return;
    temp = top;
    top = top->link;
    free(temp);
    }
    int isEmpty(){
    if(top == NULL)
    return 1;
    else
    return 0;
    }
    int Top(){
    return top->data;
    }
    int Print(){
    struct Node* temp = top;
    if(isEmpty == 1){
    printf("Stack is Empty");
    return;
    }
    printf("Top| ");
    while(temp != NULL){
    printf("%d > ",temp->data);
    temp = temp->link;
    }
    printf("|End");
    }
    int main()
    {
    int choice,enter;
    printf("--------- Welcome to Stach ---------

    ");
    while(choice =! 0){
    printf("
    Please ENTER your choice
    ");
    printf("1. Push
    ");
    printf("2. Pop
    ");
    printf("3. What is Top ?
    ");
    printf("4. Is Stack Empty ?
    ");
    printf("5. Print Stack
    ");
    printf("Choice: ");
    scanf("%d",&choice);
    printf("
    ");
    switch(choice){
    case 1: printf("Enter the number for Push
    ");
    scanf("%d",&enter);
    Push(enter);
    break;
    case 2: Pop(enter);
    printf("It's popped!
    ");
    break;
    case 3: enter = Top();
    printf("Top is = %d
    ",enter);
    break;
    case 4: enter = isEmpty();
    if(enter == 1)
    printf("Yes, It's empty
    ");
    else
    printf("Nope, It contains elements
    ");
    break;
    case 5: printf("Stack Elements:
    ");
    Print();
    break;
    default : printf("Enter numbers between 1 and 5 !");
    break;
    }
    }
    system("PAUSE");
    return 0;
    }

    • @ebut0oy
      @ebut0oy 8 ปีที่แล้ว

      +Mangoser thanks man!

  • @12121921
    @12121921 ปีที่แล้ว

    This explanation is very clear .Thank you

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

    Good job explaining the relevance of big O in the stack implementation on the linked list.

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

    to set the first node instead of the last one as top is totally brilliant

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

    very clear and straight to the point. Thank you!

  • @SamAshkon1998
    @SamAshkon1998 2 ปีที่แล้ว

    great explanation, quick and simple

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

    Sir, how can you be so good.

  • @RealMcDudu
    @RealMcDudu 8 ปีที่แล้ว

    If you make a doubly-linked-list, the cost of inserting an element at the end would be also O(1), since you could just call the global tail variable.
    i.e.: head -> n1 n2 n3.... nn

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

      D. Refaeli we can also use singlly link list and the cost of operation will be o(1) only by creating two new pointer variables which will point to last two nodes..
      Although this will require space for two more pointer variables but this will be more efficient then your solution...

  • @faiselll
    @faiselll 10 ปีที่แล้ว +8

    Nice tutorial.
    why do use malloc(sizeof(struct node*))? i thought (struct node*) is a pointer of value 4 byte but our structure (struct node) is ( 4 + 4 ) = 8 bytes . isn't it the allocation is short?
    is it enough memory allocated by doing so? thanks

    • @ononto777
      @ononto777 10 ปีที่แล้ว +7

      It's gotta be malloc(struct Node) without the star. On one of the previous videos while I was testing doubly linked list, my code was failing due to this. I scratched my head for over an hour and found I was malloc'ing size of pointer (i.e. address) rather than the Node itself. This is a classic example where debugging won't give you what you are doing wrong since it's a logical mistake. :)

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

    From this video I conclude that if I want speed and less space I should better stick with array stacks

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

    thankyou so much man for making this video. It cleared all my doubts

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

    Thanks alot! Tried so long to understand this, i finally did today😄

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

    awesome explanation

  • @allThingsYellow
    @allThingsYellow 8 ปีที่แล้ว +6

    Shouldn't the dynamic memory allocation statement be
    struct Node *temp=(struct Node*)malloc(sizeof(struct Node)) ? While using the sizeof operator here our intention is to get the size of "Node" and not the "pointer to Node".

    • @gaurav7894
      @gaurav7894 8 ปีที่แล้ว

      yes

    • @allThingsYellow
      @allThingsYellow 8 ปีที่แล้ว +2

      Naval saini Hey mister,I was right in pointing out the error.You,however,are just an ignorant guy who likes pulling people down.And just so you know,I got job offers from two IT firms a few weeks ago as a full-time programmer.Cheers :D

    • @allThingsYellow
      @allThingsYellow 8 ปีที่แล้ว

      Naval saini Good sense of grammar dude :p Infosys and Cognizant.I am sure they'll be happy to see that I make an effort to learn new things and point out errors in order to help other people :)

    • @allThingsYellow
      @allThingsYellow 8 ปีที่แล้ว

      :)

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

      I was about to correct you for not putting the asterisks, but then realized that you used them and youtube used them to make part of the comment bold.

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

    Thank you so much sir.........this vedio helps me alot.............

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

    U saved my sem sir! Thanks :-)

  • @XieQiu
    @XieQiu 8 ปีที่แล้ว

    thank you for making this. you teach really well.

  • @ayushpareek265
    @ayushpareek265 9 ปีที่แล้ว +36

    Implementation in C++
    #include
    using namespace std;
    class Stack
    {
    private:
    struct Node
    {
    int data;
    Node* link;
    };
    struct Node* top;
    public:
    Stack()
    {
    top=NULL;
    }
    void Push(int x)
    {
    Node* NewNode = new Node();
    NewNode->data = x;
    NewNode ->link = top;
    top = NewNode;
    }
    void Pop()
    {
    Node* temp= top;
    if (top==NULL)
    return;
    top=top->link;
    delete (temp);
    }
    void Print()
    {
    Node* temp = top;
    while(temp!=NULL)
    {
    cout

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

      you prefer writing the class definition inside the class or outside the class.....in our school it is preferred to write the function definition using scope resolution operator

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

      kya baaattt

  • @mountolympus1098
    @mountolympus1098 8 ปีที่แล้ว

    if we are also storing address of tail as we are doing with head then we can do insertion/deletion at end too in o(1)

  • @shefalimhadadalkar7570
    @shefalimhadadalkar7570 10 ปีที่แล้ว +9

    Exactly! the malloc shud be allocating sizeof(struct node) right? o_O

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

      Yes, I also think so.

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

      you are right

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

      god BLESSS

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

    Very helpful video. Thank you very much

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

    Indian can tell you are also one of them
    keep the great work up brrro

  • @vijayendrasdm
    @vijayendrasdm 11 ปีที่แล้ว

    Really nice videos. very helpful

  • @animeshnayan1
    @animeshnayan1 11 ปีที่แล้ว

    Your code will work, but it will cause memory leak.. you are just moving your top pointer to next node. The previous head node is still occupying space in memory. because it is dynamic memory which is not freed automatically. In pointers series, check the lesson on dynamic memory allocation and memory leak to understand this concept.

  • @ShivamRathirockzzz
    @ShivamRathirockzzz 8 ปีที่แล้ว

    You teach well.thumbs up.

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

    i love your explanations :')

  • @thenmozhikaliappan2546
    @thenmozhikaliappan2546 9 ปีที่แล้ว

    nice video sir thank u so much for the clear explanation

  • @prinxegupta
    @prinxegupta 8 ปีที่แล้ว

    really great work. thanks a lot

  • @prathyushaappala6528
    @prathyushaappala6528 7 ปีที่แล้ว

    Thanks, sir. Very useful.

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

    very good explanantion.

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

    Hello sir why r not uploading the vedios on the channel? u r teaching style is awesome.where r u?

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

    Great video thank you sir !

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

    good explanation

  • @SatyendraJaiswalsattu
    @SatyendraJaiswalsattu 9 ปีที่แล้ว

    good explanation..

  • @vatikaprasad
    @vatikaprasad 7 ปีที่แล้ว

    You are truly amazing! Thanks so much :)

  • @mohitpandey4655
    @mohitpandey4655 ปีที่แล้ว

    We miss you sir

  • @pujabhattacharya2857
    @pujabhattacharya2857 8 ปีที่แล้ว

    explanation, btw on 09:58 you got to correct top=250 and not 100, otherwise in temp the 100 value will get copied and not 250

    • @gurdyalsingh8228
      @gurdyalsingh8228 8 ปีที่แล้ว

      Puja Bhattacharya top=250,got delete by calling free function.

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

    I'm VietNamese,Thank you so much :)

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

    Thank you so much

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

    Thanks a lot!

  • @adityasharmacs1-149
    @adityasharmacs1-149 4 ปีที่แล้ว

    be hepfull please make some vedios on competitive coding

  • @keshavkapoor1515
    @keshavkapoor1515 8 ปีที่แล้ว

    kya hum data structures ke exam mai stack explain krte tym uske saath programs lihk sakte h ya sirf algorithm hi lihkne h.

  • @bhumipatel9617
    @bhumipatel9617 9 ปีที่แล้ว +2

    it's really very helpful & i nice try. thank u so much.:-)

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

      how you look back to this point ?

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

    why did you declare the variable temp using the size of the pointer instead of the size of struct nodes itself ???

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

    how would this look if you used string instead of int

  • @TheTahlia1988
    @TheTahlia1988 8 ปีที่แล้ว

    Nicely done. :)

  • @takanobu3012
    @takanobu3012 7 ปีที่แล้ว

    How would I implement a stack using a LinkedList object? Would I need to create an instance of the LinkedList class in my stack.h and call the constructor for the LinkedList object in the stack's constructor (if there is only a default constructor for LinkedList)?

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

    2 corrections (I guess)-
    1 malloc(sizeof(struct Node)) instead of malloc(sizeof(struct Node*)) PUSH function
    2 top = temp -> link instead of top = top -> link POP function

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

      basically top and temp both are pointing to the same address field i.e. 250 in the video. So, top = top->link is same as top = temp->link in that particular scenario. And for that number 1 point, yes you are correct. It was a typo.

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

    Cant thank you enough sir :)

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

    Come back please 🙏

  • @7huannp
    @7huannp 6 ปีที่แล้ว

    I don't understand about constant time or O(n) , O(1),.... Can you explain for me?

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

    *rest in peace sir :(*

  • @Sshubham489
    @Sshubham489 7 ปีที่แล้ว

    which compiler are you using?

  • @mariosactron7617
    @mariosactron7617 7 ปีที่แล้ว

    When popping from the stack why do you need to declare a temp variable. Can't you just set top = top->link; instead of top = temp->link; ? I know that is what you showed in your video but I feel like it's a mistake because you declared temp, but what's the point of declaring a temp just to free it. I feel like it's redundant.

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

      you can`t mario as if you use top=top->link then the value to which top was pointing earlier will be lost so it can`t be freed after that. so first a temp variable must be declared so that after top=top->link the memory can be freed by using free(temp) as temp will still be pointing at the value to be popped

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

    Is
    struct Node* temp=(struct Node*)malloc(sizeof(struct Node));
    the same as
    struct Node* temp=(struct Node*)malloc(sizeof(struct Node*));
    ... the code works same for both ways

  • @vighneshs5069
    @vighneshs5069 8 ปีที่แล้ว +47

    arre mere college mei aaja padane

    • @khawarmehmood1835
      @khawarmehmood1835 7 ปีที่แล้ว +7

      he can't visit your college dear, this person was died in a road accident in 2015 :'(

    • @VS-ey2lf
      @VS-ey2lf 6 ปีที่แล้ว

      Khawar Mehmood Are you serious? oh my god how do you know?

    • @VS-ey2lf
      @VS-ey2lf 6 ปีที่แล้ว +51

      Bro you said he died in 2015 last video he uploaded was oct 24, 2016. I did a little bit research and found out the person who died was humblefool(harsha), india greatest red coder, He was friend of mycodeschool(this guy name is animesh) and also a co-founder of mycodeschool. Bro half knowledge is dangerous!! Please just don't shoot arrows in the dark!!

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

      @@VS-ey2lf yes Harsha was his senior in IIIT Allahabad

    • @shivamb.3973
      @shivamb.3973 4 ปีที่แล้ว

      @Atharva Wankhede I think he was just making a joke.

  • @sivasarath1063
    @sivasarath1063 9 ปีที่แล้ว

    at 9:53 when we free temp,we are just freeing only the reference to the node but not node temp is pointed to? and isn't this way memory of machine wasted

  • @andreygoncalves2752
    @andreygoncalves2752 7 ปีที่แล้ว

    Hello, I need help.
    How do I expand the stack capacity?
    Eg every time the stack has overflow expand another 8 capacity positions.
    Excuse me for bad english.

  • @noneofurbusns3139
    @noneofurbusns3139 7 ปีที่แล้ว

    What if we write instead:
    top= temp->link
    temp=top
    free(temp)
    ?

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

    10:56 Thanks for teaching..

  • @busybanny
    @busybanny 7 ปีที่แล้ว

    so stack in linkedlist doesn't follow LIFO rule.

  • @abdelaziz.ashraf
    @abdelaziz.ashraf 2 ปีที่แล้ว

    جامد ⚡

  • @aloksonkershastri681
    @aloksonkershastri681 7 ปีที่แล้ว

    thanks

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

    Do we need to set a temp = NULL; after free(temp); ?

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

    Sir why did you stopped making videos????

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

    Does adress 0 in memory point to NULL* memory location??

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

    In pop function, in line 4 shouldnt it be
    Top= temp->link
    rather than
    Top=top->link ??

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

      Both are correct...Both top and temp are pointing to 1st node

  • @sai9692
    @sai9692 7 ปีที่แล้ว

    Is there any good reason why we do explicit type casting here.
    [i.e: struct Node* temp = (struct Node*)malloc(sizeof(struct Node*));]
    My code works without the type cast.
    [ i.e: struct Node* temp = malloc(sizeof(struct Node*); ]

    • @kyssl
      @kyssl 7 ปีที่แล้ว

      Sairam D malloc returns void pointers generally

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

    here is the implementation on c plus plus via OOPs!!
    #include
    using namespace std;
    class node
    {
    public:
    int data;
    node* next;
    };
    node* top = NULL;
    class linkedList
    {
    private:
    public:
    void push(int x)
    {
    node* newNode = new node();
    newNode->data = x;
    newNode->next = top;
    top = newNode;
    }
    void pop()
    {
    if (top == NULL)
    {
    return;
    }
    else
    {
    node* temp;
    temp = top;
    top = temp->next;
    delete temp;
    }
    }
    void print()
    {
    node* temp = top;
    if (top == NULL)
    {
    return;
    }
    else
    {
    while (temp != NULL)
    {
    cout data next;
    }
    }
    }
    int topData()
    {
    if (top == NULL)
    {
    return -1;
    }
    else
    {
    return top->data;
    }
    }
    };
    int main()
    {
    linkedList ll1;
    ll1.push(10);
    ll1.push(10);
    ll1.push(10);
    ll1.print();
    ll1.pop();
    cout

  • @Yasjunmine
    @Yasjunmine 9 ปีที่แล้ว

    thank you veeeeeeeeeeeeeeery much

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

    But what is the use of temp in pop function?

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

    have you code for this concept in c ?

  • @sarveshkaushik7528
    @sarveshkaushik7528 9 ปีที่แล้ว +15

    Instead of top=top->link
    It should be top=temp->link.

    • @rishabhshirke1175
      @rishabhshirke1175 9 ปีที่แล้ว +6

      SARVESH KAUSHIK you r right it can be like that .. but if u look at it carefully,both temp and top are pointing to same node.he declared temp and initialized to top only to store its address so he can free the memory after.dats what he had done after.

    • @SatyendraJaiswalsattu
      @SatyendraJaiswalsattu 9 ปีที่แล้ว

      +Rishabh Shirke both are pointing to the same address.

    • @rishabhshirke1175
      @rishabhshirke1175 9 ปีที่แล้ว

      +Satyendra Jaiswal Same address of what?.....The node. :)
      int a;
      int *p=&a
      p stores the address of the variable a;
      i.e pointer p is pointing to a;

    • @徐宏杰-i6w
      @徐宏杰-i6w 6 ปีที่แล้ว

      Satyendra Jaiswal thank you so much

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

    how do you implement the print function?

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

    I see that pop implementation of stack using linkedlist is not right. As you should add or remove elements from the top. The implementation illustrated in this video is removing the element which is not on top.
    But for now, you need to modify the code to be something like this
    struct node* temp= head;
    while(temp->next_node != top)
    {
    new_top = temp; // you will use it to get the element right before the one you want to remove
    temp = temp-> next_node; // you will update the temp to be looking for the next element, and then enter the loop again to check if it's the top or not
    }
    free(temp);

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

    NOICE SIR...

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

    But this is not following the property of stack.. The lifo property

  • @hossainahmed7861
    @hossainahmed7861 7 ปีที่แล้ว

    thx

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

    how to use stack using circular linked list ?

  • @sauravbhondve8307
    @sauravbhondve8307 7 ปีที่แล้ว +2

    Implementation in C++ :
    #include
    using namespace std;

    // Creating a NODE Structure
    struct node
    {
    int data;
    struct node *next;
    };
    // Creating a class STACK
    class stack
    {
    struct node *top;
    public:
    stack() // constructure
    {
    top=NULL;
    }
    void push(); // to insert an element
    void pop(); // to delete an element
    void show(); // to show the stack
    };
    // PUSH Operation
    void stack::push()
    {
    int value;
    struct node *ptr;
    coutnext=NULL;
    if(top!=NULL)
    ptr->next=top;
    top=ptr;
    cout

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

    C++ (Object Oriented implementation)
    class Node {
    public:
    int data;
    Node* next;
    };
    class Stack {
    public:
    Stack(int N)
    {
    this->head = NULL;
    size = N;
    }
    Stack()
    {
    this->head = NULL;
    }
    Node* head;
    int size;

    void pop()
    {
    if (!isEmpty())
    {
    Node* temp = head;
    head = head->next;
    delete(temp);
    size++;
    }
    else
    {
    cout data;
    else
    {
    cout data = data;
    temp->next = head;
    head = temp;
    size--;
    cout