单向链表 头尾插法
来源:互联网 发布:淘宝运费险是怎么算的 编辑:程序博客网 时间:2024/05/11 01:50
单向链表 头尾插法
#include<iostream.h>#include<conio.h> struct node{ int data; node *next; };node *createlist(int );node *createlistinvert(int );void outputlist(node *head); int main(){ int n; node *listhead=NULL; cout<<"请输入节点数目: "; cin>>n; cout<<"**************下面请您输入"<<n<<"个整数*****************\n"<<endl; if(n>0) { cout<<" ***************尾差法********************\n"<<endl; listhead=createlist(n); outputlist(listhead); cout<<" \n\n *****************头插法*********************\n"<<endl; cout<<"**************下面请您输入"<<n<<"个整数*****************\n"<<endl; listhead=createlistinvert(n); outputlist(listhead); } getch(); return 0; }//尾插法 node *createlist(int n){ node *temp=NULL,*tail=NULL,*head=NULL; int num; cout<<"请输入数据: "; cin>>num; head=new node; if(head==NULL) { cout<<"内存分配不成功,重试吧!"; return NULL; } else { head->data=num; head->next=NULL; tail=head; } for(int i=0;i<n-1;i++) { cin>>num; temp=new node; if(temp==NULL) { cout<<"内存分配不成功"; return head; } else { temp->data=num; temp->next=NULL; tail->next=temp; tail=temp; } } return head; }//头插法node *createlistinvert(int n){ node *temp=NULL,*head=NULL; cout<<"请输入数据:"; int num; cin>>num; head=new node; if(head==NULL) { cout<<"内存分配不成功!"; return NULL; } else { head->data=num; head->next=NULL; } for(int i=0;i<n-1;i++) { cin>>num; temp=new node; if(temp==NULL) { cout<<"内存分配不成功!"; return head; } else { temp->data=num; temp->next=head; head=temp; } } return head; } void outputlist(node *head) { cout<<"List: "; node *curnode=head; while(curnode) { cout<<curnode->data; if(curnode->next) cout<<" -> "; curnode=curnode->next; } cout<<endl; }
- 单向链表 头尾插法
- Python 实现带头尾指针的单向链表
- 不带头节点的头尾插法
- 单向循环链表的头插,尾插,中间插以及删除节点
- 用Python写一个简单的单向链表(包含头尾指针)
- 算法进行时--单链表(一)头尾插法
- 1.1头尾插入法建立链表
- 单向循环链表,头插,尾插,中间插入,删除等功能
- 广义表-头尾链表
- 广义表 头尾表示法表示
- 带有头尾节点的链表
- 2016年12月21日学习总结----单向循环链表操作程序(头插,尾插,中间插入,删除,逆序)
- 嵌入式 双向链表的头尾中插入法以及释放
- 同头尾合十法
- 数据结构之广义表(头尾链表存储)基本操作
- 双向链表容器list的头尾中,全部删除
- 链表的头尾倒置的一种方法
- 素数筛选法<单向链表实现>
- 编程能力的四种境界
- VS2010连接SQL Server 2008并执行查询操作
- JDBC
- input值改变事件兼容代码(用于做自动补全)
- KMP算法总结
- 单向链表 头尾插法
- c# FTP操作类
- 爱是永久相思情
- JAVA网络编程——简单的聊天程序
- [Tomcat6.0源码]组件的启动
- 【整理】双模双待、双卡双待、双模双待双通、双频手机
- QT210,U-Boot移植(3)
- Android中数据文件解析(Json解析【从服务器端获取数据并且解析,显示在客户端上面】)
- 赴台旅学前奏~台湾旅游知识普及篇