vc++ 6.0 堆栈

To implement a stack using a linked list, basically we need to implement the push() and pop() operations of a stack using linked list.

使用链接列表实现堆栈 ,基本上,我们需要使用链接列表实现堆栈push()pop()操作。

Example:

例:

Input numbers: 1,3,5,8,4,0

输入数字:1,3,5,8,4,0

We push the numbers into the stack and whenever it executes a pop() operation, the number is popped out from the stack.

我们将数字压入堆栈,每执行一次pop()操作,数字就会从堆栈中弹出。

Algorithm:

算法:

To implement the push() operation:

要实现push()操作

  1. If the Linked list is empty then create a node and point it as head of that Linked List.

    如果“链接列表”为空,则创建一个节点并将其指向该“链接列表”的头。

  2. If the Linked List is not empty then create a node with the input number to be pushed and make it head of the Linked List.

    如果“链接列表”不为空,则创建一个带有要推送的输入编号的节点,并使它成为“链接列表”的头。

To implement The pop() operation

实现pop()操作

  1. If the Linked List is already empty then do nothing. Output that empty stack.

    如果“链接列表”已经为空,则什么也不做。 输出该空堆栈。

  2. If the Linked List is not empty then delete the node from head.

    如果“链接列表”不为空,则从头删除该节点。

C++ implementation:

C ++实现:

#include<bits/stdc++.h>
using namespace std;
struct node{int data;
node* next;
};
//Create a new node
struct node* create_node(int x){struct node* temp= new node;
temp->data=x;
temp->next=NULL;
return temp;
}
//Enter the node into the linked list
void push(node** head,int x){struct node* store=create_node(x);
if(*head==NULL){*head =store;
return;
}
struct node* temp=*head;
//add the number in the front of the linked list
store->next=temp;
*head=store;
}
//pop from the stack
void pop(node** head){if(*head==NULL)
return;
struct node* temp=(*head)->next;
*head=temp;                //delete from the front
}
void print(node* head){struct node* temp=head;
while(temp){cout<<temp->data<<" ";
temp=temp->next;
}
}
int main()
{struct node* l=NULL;
push(&l,1);
push(&l,2);
push(&l,3);
push(&l,4);
push(&l,5);
push(&l,6);
cout<<"Before the pop operation"<<endl;
print(l);
pop(&l);
pop(&l);
cout<<"\nAfter the pop operation"<<endl;
print(l);
return 0;
}

Output

输出量

Before the pop operation
6 5 4 3 2 1
After the pop operation
4 3 2 1

翻译自: https://www.includehelp.com/cpp-programs/implement-stack-using-linked-list-in-cpp.aspx

vc++ 6.0 堆栈

vc++ 6.0 堆栈_在C ++中使用链接列表实现堆栈相关推荐

  1. notepad++节点_在C ++中删除链接列表的中间节点

    notepad++节点 Given a single Linked List and we have to delete the middle the element of the Linked Li ...

  2. 如何在JavaScript中实现链接列表

    If you are learning data structures, a linked list is one data structure you should know. If you do ...

  3. python3堆栈_避免python3中的堆栈溢出

    免责声明:我完全不懂计算机科学,也不知道幕后发生的任何事情的内部工作原理.教我自己使用互联网上的所有东西来编写代码.在 Python版本:Python 3.4.3 (v3.4.3:9b73f1c3e6 ...

  4. 进程handle获取线程_获取进程中的线程列表

    进程handle获取线程 The System.Diagnostics namespace contains functions that allow you to manage processes, ...

  5. 微信小程序 查找兄弟节点_使用C ++程序在链接列表中查找节点

    微信小程序 查找兄弟节点 Given a linked list and an integer N, you need to find and return index where N is pres ...

  6. c语言i++和++i程序_使用C ++程序从链接列表中消除重复项

    c语言i++和++i程序 Given a sorted linked list (elements are sorted in ascending order). Eliminate duplicat ...

  7. java获取文件目录列表_获取目录中的文件列表

    我正在开发一个C项目,我需要获取目录中的文件列表 . 我正在使用dirent.h但是在使用它时遇到了一些问题,我正在Linux下构建程序 . 当我尝试构建程序时,我收到以下错误 myClass:err ...

  8. python列表去重函数_对python中两种列表元素去重函数性能的比较方法

    测试函数: 第一种:list的set函数 第二种:{}.fromkeys().keys() 测试代码: #!/usr/bin/python #-*- coding:utf-8 -*- import t ...

  9. python中对列表排序_在Python中对嵌套列表进行排序和分组

    在Python中对嵌套列表进行排序和分组 我具有以下数据结构(列表列表) [ ['4', '21', '1', '14', '2008-10-24 15:42:58'], ['3', '22', '4 ...

最新文章

  1. 【翻译】为什么 goroutine 的栈内存无穷大?
  2. Windows 查看所有进程命令tasklist
  3. 弹性盒子内容体居右对其_弹性盒子侧轴对齐方式
  4. 牛客网 【每日一题】[SCOI2009]粉刷匠
  5. java中大数字表示什么_JAVA中大数字的的处理:BigInteger和BigDecimal
  6. cin gt gt a用c语言怎么写写,cin、cin.get()、cin.getline()、getline()、gets()等函数的用法...
  7. flutter 底部动画导航栏
  8. 气候变化与 计算机网络,北京理工大学:气候变化综合评估模式研究获立项
  9. 剑指offer——30.包含min函数的栈
  10. weak属性需要在dealloc中置nil么?
  11. python抓取微信公众号文章_如何使用python3抓取微信公众号文章,了解一下?
  12. altium Designer布等长线、蛇形线
  13. vs code 国内镜像源
  14. Java实现一个打飞机的小游戏【附源码】
  15. SH-SSS丨《ISSD: 基于迭代式语音分离的说话人日志系统》论文线上分享
  16. 【戏言、昔言、惜言】谭惜言写了一辈子的戏,真情假意,全在戏言里。
  17. 通俗解释NLP任务四种评价指标(BLEU,METOR,ROUGH,CIDEr)
  18. K-means聚类算法及其各种变形模型的实验分析
  19. Yuga Labs大举扩张,“猿”宇宙已经不远了?
  20. 高德地图第三方工具网站

热门文章

  1. c语言 指针到字符串,C语言中的指针和字符串
  2. jquery点击非div区域隐藏div
  3. Table Dragger - 简单的 JS 拖放排序表格插件
  4. HTML5 拖放、交换位置
  5. 进入登录页时,用户名输入框自动聚焦、按enter键让密码框聚焦,完整输入信息后登录
  6. ie 浏览器布局中的 offset
  7. 浏览器记住密码的自动填充Input问题完美解决方案
  8. 洛谷 P1795 无穷的序列_NOI导刊2010提高(05)
  9. 000 快速排序算法
  10. VB调用VC DLL函数