c实现带表头的单链表的创建、测长及打印
2015-03-27 21:10
337 查看
#include <iostream> #include <malloc.h> using namespace std; typedef struct student { int data; struct student *next; } node; //带头节点 node *create(){ node *head, *p, *s; int x, cycle=1; head = (node *)malloc(sizeof(node)); p=head; while(cycle){ printf("please input the data(0 is end):"); scanf("%d",&x); if(x!=0){ s= (node *)malloc(sizeof(node)); s->data=x; s->next=NULL; printf("%d\n",s->data); p->next=s; p=s; } else cycle=0; } return head; } int length(node* head) { int counter=0; head = head->next; while (head!=NULL){ counter++; head=head->next; } return counter; } void print(node *head){ head = head->next; while (head!=NULL){ printf("%d ", head->data); head = head->next; } printf("\n"); } int main() { node *head; head = create(); printf("the length of list:%d \n" , length(head)); print(head); return 0; }
相关文章推荐
- 编程实现一个单链表实现创建、测长以及打印
- [002]链表笔记--编程实现一个单链表的创建/测长/打印
- 实现单链表的创建、打印、插入、删除、逆置
- C++实现单链表的创建和打印
- 问题9:编程实现一个单链表的建立/测长/打印以及结点的删除。
- C/C++ 创建单链表,取链表长度,打印链表
- 单链表的创建、计数打印、删除与插入操作
- 用c实现HASH表创建、插入、查找、删除、打印(欢迎高手指点)
- 实现 DataGrid 在打印时,每页都可显示 表头
- 单链表的创建、测长、打印、插入和删除
- 单链表详解(创建,插入,删除,打印)
- 讨论创建基于WSE的报表打印服务及其实现
- 实现单链表创建、插入、删除、打印功能
- SL复合表头报表实现(包含导出和打印)
- 用c实现HASH表创建、插入、查找、删除、打印
- 用C#实现单链表(创建单链表,在头部插入)
- JS+CSS 实现打印分页 每页都有表头和页尾
- 讨论创建基于WSE的报表打印服务及其实现
- java实现单链表的初始化,创建,删除,插入,查找,排序,同项删除,退出等功能
- 单链表的创建、插入、删除;创建采用两种不同的方式:一种是从表头到表尾,另一种是从表尾到表头!