函数与链表
来源:互联网 发布:淘宝买家拒签怎么办 编辑:程序博客网 时间:2024/05/16 15:32
#include <stdio.h>
#include <stdlib.h>
typedef struct Num //结构体的声明
int data;
struct Num *next;
}Num;
Num * createlink(int len) //链表创建函数
{
Num *p = (Num *)malloc(sizeof(Num));
Num *head=p;
int i=0;
p->data=i+1;
p->next=NULL;
while (i<len-1)
{
i++;
p->next=(Num *)malloc(sizeof(Num));
p->next->data=i+1;
p->next->next=NULL;
p=p->next;
}
return head;
}
void printlink(Num *p) //链表输出函数
{
while (p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
}
}
void freelink(Num *p) //链表释放函数
{
Num *q;
while (p!=NULL)
{
printf("%d\n",p->data);
q=p->next;
free(p);
p=q;
}
}
int main(void)
{
int i;
printf("请输入要创建的链表的长度:");
scanf("%d",&i);
Num *p=createlink(i);
printlink(p);
freelink(p);
return 0;
}
0 0
- 函数与链表
- 函数指针与链表结合举例
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- 虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- 虚函数表与虚函数指针
- C++虚函数与虚函数表
- 虚函数与虚函数表
- C++虚函数与虚函数表
- C++虚函数与虚函数表
- 虚函数与虚函数表
- 虚函数与虚函数表
- Annotation 使用笔记(二) 注解生成SQL脚本
- A program to check if a binary tree is BST or not
- Linux磁盘分区
- POJ 3281 Dining
- 简单的模态对话框ModalDialog -- 源码分享
- 函数与链表
- WCF 服务第一次调用慢的问题
- 《Head First Design Patterns》读书笔记之模板模式
- wifidog原理
- Android开发之解析XML并实现三级联动效果
- Oracle EBS避免长时间不登录重新登录
- android Google Map V2内容以及疑难杂症
- poj 2785 4 Values whose Sum is 0(双向搜索)
- rman恢复之丢失非当前联机重做日志文件(读书笔记)