单链表的建立/测长/打印

单链表的建立/测长/打印

分类:程序员面试宝典(四)

#include<iostream>#include<stdio.h>#include<string.h>#include<conio.h>using namespace std;typedef struct student{int data;struct student *next;}node;node *creat(){node *head, *p, *s;int x, cycle = 1;head = (node*)malloc(sizeof(node));p = head;while (cycle){printf("\n please input the data:");scanf("%d", &x);if (x != 0){s = (node*)malloc(sizeof(node));s->data = x;printf("\n%d", s->data);p->next = s;p = s;}elsecycle = 0;}head = head->next;p->next = NULL;printf("\n yyy %d", head->data);return (head);}int length(node *head){int n = 0;node *p;p = head;while (p != NULL){p = p->next;n++;}return (n);}//单链表打印void print(node *head){node *p; int n;n = length(head);printf("\n Now,These %d records are:\n", n);p = head;while (p != NULL){printf("\n uuu %d ", p->data);p = p->next;}}

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇关键字static的作用下一篇单链表删除节点

顶0踩0

,在向山靠近一点,才发现这座山,好象一位诗人遥望远方,

单链表的建立/测长/打印

相关文章:

你感兴趣的文章:

标签云: