c语言链队列的构建
来源:互联网 发布:js中的tostring方法 编辑:程序博客网 时间:2024/04/29 04:00
改代码实现的是输入一串字符然后再屏幕上输出,只是为了验证队列。
c文件
#include <stdio.h>
#include<malloc.h>
#include <string.h>
typedef struct User_type
{
char data;
struct User_type *next;
} User_type;
#include "Array.h"
/*
//初始化队列
void initArray(Array **head);
//销毁队列
void destroyArray(Array **head);
//入队列
void push(Array *head,User_type *data);
//出队列
void pop(Array *head,User_type *data);
*/
int main()
{
Array *head=NULL;
User_type Data;
char a;
initArray(&head);
scanf("%c",&a);
while(a!='0')
{
Data.data=a;
push(head,&Data);
scanf("%c",&a);
}
while(head->front->next!=NULL)
{
pop(head,&Data);
printf("%3c",Data.data);
}
destroyArray(&head);
}
h文件
#ifndef _ARRAY_
#define _ARRAY_#include <malloc.h>
#include <stdio.h>
typedef struct Array
{
User_type *front;
User_type *end;
}Array;
//初始化队列
void initArray(Array **head);
//销毁队列
void destroyArray(Array **head);
//入队列
void push(Array *head,User_type *data);
//出队列
void pop(Array *head,User_type *data);
void pop(Array *head,User_type *data)
{
User_type *p=NULL,*q=NULL;
p=head->front->next;
if(head->end->next==NULL||p==NULL)
{
printf("非法操作!");
}
else
{
data->data=head->front->next->data;
q=p;
head->front->next=p->next;
free(q);
}
}
void push(Array *head,User_type *data)
{
User_type *p=NULL,*q=NULL;
q=head->front->next;
p=(User_type *)(malloc(sizeof(User_type)));
if(q==NULL)
{
head->front->next=p;
head->end->next=p;
}
else
{
head->end->next->next=p;
head->end->next=p;
}
p->data=data->data;
p->next=NULL;
}
void destroyArray(Array **head)
{
User_type *p=NULL,*q=NULL;
q=(*head)->front->next;
p=q;
while(p!=NULL)
{
p=q->next;
free(q);
q=p;
}
free((*head)->front);
free((*head)->end);
free(*head);
}
void initArray(Array **head)
{
if(*head)
{
printf("非法操作!");
}
else
{
(*head)=(Array *)(malloc(sizeof(Array)));
if(*head)
{
(*head)->front=(User_type *)(malloc(sizeof(User_type)));
(*head)->end=(User_type *)(malloc(sizeof(User_type)));
(*head)->front->next=NULL;
(*head)->end->next=NULL;
}
else
{
printf("空间不足!");
}
}
}
#endif
0 0
- c语言链队列的构建
- C语言:链队列
- c语言:链队列
- C语言链队列的基本操作
- 链队列的实现 C语言
- 链队列的C语言实现
- 链队列的C语言实现
- 链队列的c语言实现
- C语言基于链表的队列
- c语言:链队列的实现
- 链队列的c语言实现
- 队列的C语言实现
- C语言队列的实现
- c语言队列的实现
- 队列的c语言实现
- 队列的C语言实现
- 队列的C语言实现
- 队列的实现C语言
- C# 中双重检测单例模式
- shape使用
- maven: 打包可运行的jar包(java application)及依赖项处理
- 【Android】数据库SQLite
- 深入.NET平台和C#理解--第二章上级(1,2)--积分更新和计算机ID
- c语言链队列的构建
- 常用地址
- js延时加载
- 利用map()函数,把用户输入的英文名字,变为首字母大写,其他小写的规范名字&&键盘输入的整数相加
- 关于按钮layout_gravity设置为right不管用的问题
- GC算法和种类【重要】
- 每天一个 Linux 命令(30): chown命令
- 001 - 全、半角 英文切换
- SpringBoot Batch 实战