链表
来源:互联网 发布:kiki软件收费吗 编辑:程序博客网 时间:2024/06/08 02:22
#include<iostream.h>typedef struct node{int data;node *next;}*ptrn;ptrn creatlink(){ptrn head,p1,p2,p3;head=new node;int a;int b;p1=0;cout<<"输入一个整数表示链表中的一个元素,以-1表示结束"<<endl;for(int i=0;;i++){ cin>>a;if(a==-1)break;else{p2=new node;p2->data=a;if(p1==0){p1=p2;p3=p2;}else{ p3->next=p2; p3=p2;}}}if(p1)p3->next=0;head=new node;head->next=p1;return head;}int linklength(ptrn head){ptrn temp;temp=head->next;for(int j=1;;j++){temp=temp->next;if(temp==0)break;}return j;}ptrn oppositelink(ptrn head){ptrn pa,pb,pc;pa=0;pb=new node;ptrn temp1;int n=linklength(head);for(int i=0;i<n;i++){temp1=head->next;for(int j=n-i;j>0;j--){ pb=temp1; temp1=temp1->next;}if(pa==0){pa=pb;pc=pb;}else{pc->next=pb;pc=pb;}}if(pa)pc->next=0;head->next=pa;return head;}void main(){ptrn head=creatlink();linklength(head);cout<<"此链的倒序为"<<endl; head=oppositelink(head);ptrn tem;tem=head->next;for(int k=0;k<linklength(head);k++){cout<<tem->data<<endl;tem=tem->next;}}
0 0
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- Android SDK在线更新镜像服务器
- Java垃圾回收机制
- 拓园情
- 《PHP核心技术与最佳实践》读书笔记(面向接口与反射篇)
- Deep learning 学习(一)
- 链表
- eclipse svn拷贝团队 队员文件 到项目导致svn失去版本控制等错误原因
- 编程题:动态规划---从左上角到右下角的价值最大的路径
- 函数模板与类模板
- 新建controllers/models/views及数据库连接优化
- 链表内容排序
- 支持向量机SVM(一)
- 绘图 画笔特效处理2
- 大数据工程师:大数据的java基础 第八周