您的位置:首页 > 理论基础 > 数据结构算法

C 队列之数据结构

2013-04-16 09:46 113 查看
#include<stdio.h>

#include<stdlib.h>

typedef struct List

{

int * elem;

List * next;

}Note,*Link;

typedef struct Sqr

{

Link front;

Link rear;

}sqr;

void init(sqr &s)

{

s.front=s.rear=(Link)malloc(sizeof(Note));

if(!s.front) exit(0);

s.front->next=NULL;

}

void creat(sqr &s)

{

int i;

for(i=0;i<5;i++)

{

Link p=(Link)malloc(sizeof(Note));// 尼玛 坑爹呀 弄了半天就是分空间出错了(如果把这句放在for循环外面 那么每次赋值就把上次的覆盖了 地址就只有这么一个嘛 )

if(!p) exit(0);

scanf("%d",&p->elem);

p->next=NULL;

s.rear->next=p;

s.rear=p;

}

}

void display(sqr &s)

{

printf("头为: %d\n",s.front->next->elem);

}

void main()

{

sqr s;

init(s);

creat(s);

display(s);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: