chapter_stack_and_queue/stack/ #64
Replies: 73 comments 94 replies
-
想问一下,用链表实现栈的pop操作时,删除栈顶还需要把原来的栈顶的内存delete掉吗,或者说进行或不进行delete都行呢? |
Beta Was this translation helpful? Give feedback.
-
仅针对Java,给大家补充一点知识:Java中是有专门的栈实现类的,就是java.util.Vector,Stack在Java中是继承于Vector,这里说的是1.8版本,使用了Vector底层的数据结构,底层都是使用数组实现的。
以后大家在LeetCode中刷题时,会经常用到这个类,可以提前先了解一下。 |
Beta Was this translation helpful? Give feedback.
-
请问出栈的这个方法中返回被pop节点的值的意义是什么?
|
Beta Was this translation helpful? Give feedback.
-
c++的版本,pop接口应该增加int返回值并在实现最后return num,以保持设计逻辑的同步(栈 pop() 接口的设计习惯,一般都会返回出栈元素),要不然int num = top();就多余了。 没找到修改的办法,只好评论麻烦作者自己修改了 |
Beta Was this translation helpful? Give feedback.
-
Deque stack = new LinkedList<>();这样是否可以呢,如果是当作队列直接换个名称 |
Beta Was this translation helpful? Give feedback.
-
初学者很多只学C,想求个C语言的代码~非常感谢 |
Beta Was this translation helpful? Give feedback.
-
栈也可以用作括号检查 |
Beta Was this translation helpful? Give feedback.
-
麻烦问一下 |
Beta Was this translation helpful? Give feedback.
-
好的,谢谢你 超级开心😁帮我解答了我得困惑
…---Original---
From: "Yudong ***@***.***>
Date: Fri, Apr 7, 2023 16:59 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [krahets/hello-algo] chapter_stack_and_queue/stack/ (Discussion#64)
Hi 也可以显式地将 next 设置为空,不设置也行,stackPeek = stackPeek.next; ,这一步后原来的 stackPeek 已经无法被访问到了,可以视为已经从链表中删除了。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
典型应用中 |
Beta Was this translation helpful? Give feedback.
-
您好k哥,链表出栈的c语言代码, |
Beta Was this translation helpful? Give feedback.
-
手敲了一遍链表实现的栈,很有成就感 |
Beta Was this translation helpful? Give feedback.
-
在Java中,Stack是一种继承自Vector的类,用于实现后进先出(LIFO)的数据结构。然而并不推荐使用Stack,主要有以下几个原因:
综上所述,Java更倾向于使用其他数据结构来实现栈的功能,如ArrayList、LinkedList或ArrayDeque。这些数据结构提供了更好的性能、更多功能和更高的灵活性。 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
作者您好! |
Beta Was this translation helpful? Give feedback.
-
自己写的时候每次push都把新节点挂到top后面,结果写pop的时候卡住了,怎么想也想不到如何找到pop的前驱,甚至想到了双向链表。。。结果看作者的答案,每次push把top挂到新节点后面,怎么就没想到头插法呢,还是菜啊。。。。 |
Beta Was this translation helpful? Give feedback.
-
c++代码中,/* 初始化栈 */ |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
pop函数中 |
Beta Was this translation helpful? Give feedback.
-
JS 版本: isEmpty() { push(value) {
} class ArrayStack{ |
Beta Was this translation helpful? Give feedback.
-
之前学data structure的时候只是单纯学习了stack的概念&代码,现在结合应用、array与linked list的对比就一下子变得更有趣了! |
Beta Was this translation helpful? Give feedback.
-
在linkedlist_stack.cpp好像没有定义freeMemoryLinkedList()这个函数,我写成(C++版本) |
Beta Was this translation helpful? Give feedback.
-
Java数组实现:
|
Beta Was this translation helpful? Give feedback.
-
5.1.2中实现栈的方法里「基于链表实现」中的Python代码中,「pop」函数的 「num = self.peek」是不是笔误?应该改为「num = self._peek」? |
Beta Was this translation helpful? Give feedback.
-
人民邮电出版社24年2月第1版,86页,即本节内的5.1.2基于数组实现的栈,python代码,is_empty函数有错误,书中的是 return self._size == 0 ,我看到线上的已经更正为 return self.size() == 0 了 |
Beta Was this translation helpful? Give feedback.
-
C#
|
Beta Was this translation helpful? Give feedback.
-
day04 |
Beta Was this translation helpful? Give feedback.
-
栈遵循先入后出的原则,因此我们只能在栈顶添加或删除元素。然而,数组和链表都可以在任意位置添加和 |
Beta Was this translation helpful? Give feedback.
-
某些语言可能没有专门提供栈类,这时我们可 |
Beta Was this translation helpful? Give feedback.
-
栈的特点是先进后出,基本入栈和出栈都是在栈顶处理的,文中说“ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
chapter_stack_and_queue/stack/
Your first book to learn Data Structure And Algorithm.
https://www.hello-algo.com/chapter_stack_and_queue/stack/
Beta Was this translation helpful? Give feedback.
All reactions