Heap, stack, stack, the difference between the queue

Stack is a kind of a data item data structure in sequence, only one end (referred to as a top of the stack (Top)) to insert and delete data items.

Important: Heap: any order       Stack: LIFO (Last-In / First-Out )

 

 stack  

Heap: What is the heap? How should we understand it?

① usually a stack array object can be seen as a tree. Heap always meet the following properties:

  • The stack is always a node value is not larger than or not less than the value of its parent node;
  • Heap always a complete binary tree.
  • The root node called the largest heap max heap or stack large root, root smallest minimum heap heap called a root or a small heap. Common reactor with a binary heap, Fibonacci heap and so on.

② heap at runtime rather than at compile time, an application memory size. That dynamic allocation of memory, and it is no different for general access memory access.

③ heap is running when the application program requests the operating system memory allocated to itself, generally the process of application / administration.

Refers to dynamic memory heap ④ application program is running, but only refers to a method for the stack (i.e., after the advanced) stack used.

  

 

Stack 

Stack: What is the stack? How should we understand it?

  • ① stack (Stack), also known as the stack, which is a linear form of operation is limited. With the restriction that only permits insertion and deletion operation at one end of the table. This input is called the stack, relatively, and the other end is called the bottom of the stack.
  • ② stack is a barrel, after put to acquire it, it would have some of the following things to come out after it and so to come out (last out)
  • ③ stack (Stack) is an operating system in the establishment of a process or thread (thread-support multithreaded operating system) storage area created for this thread, this area has the characteristics of the FIFO can be specified at compile time needed the size of the Stack.

     

Stack  

Stack: What is the stack? How should we understand it?

Note: In fact, the stack is the stack itself, just changed the name of the abstract.

Stack features: the last object in the stack is always the first to put out, this feature is usually referred to as last in first out (LIFO) queue. Stack defines a number of operations. The two most important are PUSH and POP. A PUSH operation is added at the top of the stack element. Instead POP operation, a removing element in the top of the stack, and a reduced size of the stack.

 

   

 

to sum up:

Heap, stack difference Summary:

1. Stack space allocation

   ①栈(操作系统):由操作系统自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。

  ②堆(操作系统): 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收,分配方式倒是类似于链表。

2.堆栈缓存方式

   ①栈使用的是一级缓存, 他们通常都是被调用时处于存储空间中,调用完毕立即释放。

  ②堆则是存放在二级缓存中,生命周期由虚拟机的垃圾回收算法来决定(并不是一旦成为孤儿对象就能被回收)。所以调用这些对象的速度要相对来得低一些。

3.堆栈数据结构区别

   ①堆(数据结构):堆可以被看成是一棵树,如:堆排序。

  ②栈(数据结构):一种先进后出的数据结构。

 

队列:

队列:什么是队列?又该怎么理解呢?

  • ①队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表。进行插入操作的端称为队尾,进行删除操作的端称为队头。
  • ②队列中没有元素时,称为空队列。
  • ③建立顺序队列结构必须为其静态分配或动态申请一片连续的存储空间,并设置两个指针进行管理。一个是队头指针front,它指向队头元素;另一个是队尾指针rear,它指向下一个入队元素的存储位置。
  • ④队列采用的FIFO(first in first out),新元素(等待进入队列的元素)总是被插入到链表的尾部,而读取的时候总是从链表的头部开始读取。每次读取一个元素,释放一个元素。所谓的动态创建,动态释放。因而也不存在溢出等问题。由于链表由结构体间接而成,遍历也方便。(先进先出)

      

 

区别: 

堆、栈、队列之间的区别是?

  • ①堆是在程序运行时,而不是在程序编译时,申请某个大小的内存空间。即动态分配内存,对其访问和对一般内存的访问没有区别。
  • ②栈就是一个桶,后放进去的先拿出来,它下面本来有的东西要等它出来之后才能出来。(后进先出)
  • ③队列只能在队头做删除操作,在队尾做插入操作.而栈只能在栈顶做插入和删除操作。(先进先出)

Guess you like

Origin www.cnblogs.com/chen8023miss/p/11208142.html