数据结构之单链表
来源:互联网 发布:淘宝店招设计方法 编辑:程序博客网 时间:2024/06/03 19:33
/*****************************\*数据结构之单链表*IDE:VS2010\*****************************/#include <iostream>using namespace std;//定义节点类型typedef struct node{int data;struct node* next;}node;//创建单链表 node* create(){node* head, *cur, *end;head = (node*)malloc(sizeof(node));head->data = 0;head->next = NULL;end = head;int data;while(1){cout<<"请输入数据: ";cin>>data;if(data == 0)break;cur = (node*)malloc(sizeof(node));cur->data = data;end->next = cur;end = cur;end->next = NULL;}return head;}void testCreate(void){node* list = create();int count = 0;cout<<"\n单链表:"<<endl;while(list->next){cout<<"第"<<++count<<"个数据为 "<<list->data<<endl;list = list->next;}}//获取链表长度int getLength(node* node){int count = 0;while(node->next){count++;node = node->next;}return count;}//判断链表为满或者为空bool isEmpty(node* node){/*另一种方法:int len = getLength(node);return len==0 ? true : false;*/if(node->next == NULL)return true;return false;}bool isFull(node* node, int max_len){int len = getLength(node);return len==max_len ? true : false;}//删除数据位data的节点bool deleteNode(node* node, int data){if(!isEmpty(node)){while(node){if(node->next->data == data)//从第一个节点(不是头结点)开始{node->next = node->next->next;return true;}node = node->next;}}return false;}//在pos位置插入节点bool insertNode(node* hnode, node* insert_node, int pos, int max_len){if(isFull(hnode,max_len) || pos>max_len || pos<=0)return false;int count = 0;while(hnode){count++;if(pos == count){insert_node = hnode->next;hnode = insert_node;return true;}}return false;}int main(){testCreate();return 0;}
0 0
- 数据结构学习之单链表
- java数据结构之单链表
- 数据结构之单链表
- 数据结构学习之单链表
- 数据结构之单链表反转
- 数据结构之单链表
- 数据结构之, 单链表
- 数据结构之单链表
- 数据结构之单链表
- C++数据结构之单链表
- C++数据结构之单链表
- 数据结构之单链表
- 数据结构之单链表
- 大话数据结构之单链表
- C数据结构之单链表
- 数据结构基础之单链表
- javascript 数据结构 之 单链表
- 数据结构之单链表操作
- 内核模块加载顺序的控制
- Bitmap.compress方法,在不同机器,不同系统上,保存出来的图片的效果和大小都会不一样
- linux网络编程2-服务器设计
- 在基于对话框的程序中高级定制Web控件
- hdu-1325-Is It A Tree?--并查集判断是否是一棵树
- 数据结构之单链表
- CS/BS架构区别
- Boost编程之--慎用线程的this_thread::yield()方法
- redis 命令汇总
- MongoDB安装成为Windows服务及日常使用遇到问题总结
- OpenGL: 绘制按钮
- Java中-classpath和路径的使用
- java web开发:ajax技术(一)——局部刷新技术的实现
- 宏定义的妙用