链表转置实现
来源:互联网 发布:sql语句大全 创建用户 编辑:程序博客网 时间:2024/06/06 00:17
链表转置功能实现,不足之处 ;还请指正
#include <stdio.h>#include <stdlib.h>typedef struct Listnode{ int nodedata; struct Listnode* next;}Listnode, *pListnode;//create list //return value the number of node created//param the head of the listnodeint CreateListnode(pListnode head, int nodenumber){ int ret = 0; if(NULL == head) { return ret; } int input = 0; Listnode* front = NULL; Listnode* rear = head; //conect for(int i = 0; i < nodenumber; i++) { front = (Listnode*)malloc(sizeof(Listnode)); if(NULL != front) { scanf("%d", &input); front->nodedata = input; front->next = NULL; } rear->next = front; //append rear = rear->next; ++ret; } return ret;}
bool Traversallist(pListnode head){ bool ret = false; if(NULL == head) { return ret; } Listnode* p = head->next; while(p) { printf(" %d", p->nodedata); p = p->next; } printf("\n"); ret = true; return ret;}
bool ConvertList(pListnode head){ bool ret = false; if(NULL == head) { return ret; } Listnode* rear = head->next; Listnode* front = head->next->next; //init the ptr Listnode* p = front; if(NULL == p) //only one element { ret = true; return ret; } rear->next = NULL; //disconnect the list while(NULL != p) //get the current element { front = front->next; //insert the element head->next = p; p->next = rear; rear = p; p = front; } ret = true; return ret;}
int releaseListnode(Listnode* head){ int ret = 0; Listnode* rear = head->next; Listnode* front = head->next; while(NULL != rear) { front = front->next; free(rear); rear = NULL; rear = front; ++ret; } printf("The release number of element is %d\n", ret); return ret;}
int main(){ printf("sizeof(Listnode) == %d\n", sizeof(Listnode)); pListnode mynode = (pListnode)malloc(sizeof(Listnode)); mynode->next = NULL; printf("Please Input the number for the node:"); int nodecount = 0; scanf("%d", &nodecount); int nodenumber = CreateListnode(mynode, nodecount); printf("nodenumber ===== %d\n", nodenumber); Traversallist(mynode); printf("\n after convert the list:\n"); bool ret = ConvertList(mynode); Traversallist(mynode); int relnum = releaseListnode(mynode); free(mynode); mynode = NULL; return 0;}
- 链表转置实现
- 实现
- 实现
- 红黑树实现 实现代码
- java实现排列组合实现
- 实现Runnable 实现线程
- 实现ViewPager多种实现
- 双向LSTM实现实现
- 实现缓存 java实现
- 三子棋的实现的实现的实现
- 四则运算实现
- 继承实现
- 重载实现
- 实现缩略图
- split实现
- 实现缩略图
- wmi实现
- 实现缩略图
- 快速排序算法的Java实现
- Ubuntu12.04下PHP,APACHE,MYSQL配置
- autossh配置socks代理
- Android驱动程序开发和调试环境配置
- Air for ANE:打包注意的地方
- 链表转置实现
- linux 设置语言环境
- [ffmpeg]在Ubuntu成功编译FFmpeg并生成ffplay
- lsof
- oracle_code
- 【<私活案例1>】 某游戏网首页PS设计和Html静态效果源码
- 程序员练级攻略
- java.lang.RuntimeException: Stub!
- 可恨又可爱的404(未完待续)