C/C++ | 27-19 写出程序把一个链表中的接点顺序倒排
2017-07-27 18:41
495 查看
#include <cstdio> #include <deque> #include <algorithm> #include <iterator> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <assert.h> using namespace std; typedef struct LNode { int data; struct LNode *next; }LNode; LNode *CreateLink(int num) // 构造 { int i = 1; LNode *head, *tail, *p; head = (LNode *)malloc(sizeof(LNode)); tail = head; while (num--) { p = (LNode *)malloc(sizeof(LNode)); p->data = i; tail->next = p; tail = p; i++; } tail->next = NULL; return head; } LNode *FindLink(LNode *head, int X) //查找 { assert(head != NULL); LNode *chick = head->next; while (chick != NULL) { if (chick->data == X) return chick; else chick = chick->next; } return NULL; } void DeleteLink(LNode *head, int X) //删除 { assert(head != NULL); LNode *p; LNode *q; p = FindLink(head, X); q = p->next; p->data = q->data; p->next = q->next; free(q); } LNode *inverseLink(LNode *head) { assert(head != NULL); LNode *p, *q, *r; p = head; q = p->next; while (q != NULL) { r = q->next; q->next = p; p = q; q = r; } head->next = NULL; head = p; return head; } int main() { LNode *head = CreateLink(5); head=inverseLink(head); // 这里要对head重新进行写,函数里面对head并不保存。 system("pause"); return 0; }
相关文章推荐
- 用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。写出C/C++程序(链表)
- 练习1-19 编写函数 reverse(s),将字符串s 中的字符顺序颠倒过来。使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序。
- C++写的一个链表程序
- 用c++写一个顺序表的简单操作程序
- 颠倒一个链表的顺序 C++
- 花了差不多一个半小时写了一个基于C++的链表程序,现在发上来,大家多给点意见啊
- 练习 1-19 编写函数 reverse(s),将字符串s 中的字符顺序颠倒过来。使用该函数 编写一个程序,每次颠倒一个输入行中的字符顺序。
- C/C++ | 28-20 写出程序删除链表中的所有节点
- 请写出一个程序,对于一个m行,m列的(1<m<10)的方阵,求其每一行,每一列及 主对角线元素之和,最后按照从大到小的顺序依次输出
- 问题:利用 C++的各种控制语句编写一个万年历程序。 要求:显示任何年份的日历,日历以月份顺序排列,每月以星期顺序排列,类似于一 般挂历上的格式。
- 27_下面是一个完整的C++程序.CPP
- 日常联系:一个C++程序完成链表的增加结点、删除结点、打印、查询、逆序等操作
- 我的一个穿越C++和JAVA的程序(流星程序集之七)
- C++反汇编揭秘1 – 一个简单C++程序反汇编解析 (Rev. 3)
- c++做一个计算两向量夹角的程序
- 通过一个c++程序来理解两个指针的赋值
- C++文本查询程序 定义类管理数据 用引用共享数据 不用智能指针 C++Primer练习12.27
- 我的第十八个C++上机报告(编程序,输出1/3-3/5+5/7-7/9…+19/21的结果)
- C++的一个输出方阵程序
- 一个java调用c++程序的实例(jni)