输入一个链表的头结点,从尾到头反过来打印出每个结点的值
来源:互联网 发布:网络交友的危害英语 编辑:程序博客网 时间:2024/04/27 14:13
#include <iostream>#include <string.h>#include <stdlib.h>#include <stack>using namespace std;struct Node{int data;struct Node* next;};struct Node* create_list(int len){if (len <= 0)return NULL;struct Node* head;struct Node* tmp;struct Node* pre;for (int i=0; i<len; i++){if (i == 0){head = tmp = new struct Node;cin >> tmp->data;tmp->next = NULL;pre = tmp;continue;}tmp = new struct Node;cin >> tmp->data;tmp->next = NULL;pre->next = tmp;pre = tmp;}return head;}void visit(const struct Node *head){if (head == NULL)return;const struct Node *tmp;tmp = head;while (tmp){cout << tmp->data;tmp = tmp->next;}}void free_list(struct Node *head){if (head == NULL)return;struct Node *tmp;while (head){tmp = head;head = head->next;delete tmp;}}int main(){struct Node *head = create_list(5);visit(head);cout << endl;stack<int> sts;struct Node* tmp = head;while (tmp){sts.push(tmp->data);tmp = tmp->next;}while (sts.size() != 0){cout << sts.top();sts.pop();}cout << endl;free_list(head);return 0;}
0 0
- 输入一个链表的头结点,从尾到头反过来打印出每个结点的值
- 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值
- 输入一个链表的头结点,从尾到头反过来打印每个结点的值
- 输入一个链表的头结点,从尾到头反过来打印出每个节点的值。
- 输入一个链表的头结点,从尾到头反过来打印出每个节点的值
- 输入一个链表的头结点,从尾到头反过来打印每个节点的值。
- 输入一个链表的头结点,从尾到头反过来打印每个节点的值。
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值。
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 输入一个链表的头结点,从尾到头反过来打印每个结点的值——5
- 题目:输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 题目:输入一个链表的头结点,从尾到头反过来输出每个结点的值
- 一个新人入职2个月的感悟
- 开发者不容错过的12款开源JavaScript库
- svn第一篇----入门指南
- 04Junit Junit4的使用说明
- lua bit 函数
- 输入一个链表的头结点,从尾到头反过来打印出每个结点的值
- 使用tcgetattr函数与tcsetattr函数控制终端
- MFC应用程序中处理消息的顺序
- linux m4文件
- PHP网站培训机构助力你成为IT精英
- 第一个CSDN博客,记录这两天遇到的一个问题,是的,是问题
- C++ 函数(Functions)
- 各种总线match匹配函数
- apache 和 nginx 伪静态