2y22号
队列链表
#include<stdio.h>
#include<stdlib.h>
#include"LINK.h"
link_pos* creat_queue()
{
link_pos* pos=(link_pos*)malloc(sizeof(link_pos));
pos->first=(my_queue*)malloc(sizeof(my_queue));
if(NULL==pos->first)
{
printf("创建失败\n");
return NULL;
}
pos->first->BLdae.len=0;
pos->first->NEXT=NULL;
pos->end=pos->first;
return pos;
}
void insert_LINK(link_pos*pos,typdate num)
{
my_queue*new_temp=(my_queue*)malloc(sizeof(my_queue));
if(NULL==new_temp)
{
printf("创建失败1\n");
return ;
}
new_temp->NEXT=NULL;
new_temp->BLdae.date=num;
//尾插链接
new_temp->NEXT=pos->end->NEXT;
pos->end->NEXT=new_temp;
//更新end
pos->end=pos->end->NEXT;
pos->first->BLdae.len++;
}
//头删出队
typdate out_link(link_pos*pos)
{
if(pos->first->NEXT==NULL)
{
printf("队为空");
return -1;
}
typdate temp;
temp=pos->first->NEXT->BLdae.date;
my_queue *P=pos->first->NEXT;
pos->first->NEXT=pos->first->NEXT->NEXT;
pos->first->BLdae.len--;
free(P);
return temp;
}
//遍历
void BL(link_pos*pos)
{
if(pos->first->NEXT==NULL)
{
printf("链表为空");
return ;
}
my_queue*p=pos->first;
while(p->NEXT!=NULL)
{
p=p->NEXT;
printf("%d ",p->BLdae.date);
}
printf("\n");
printf("长度%d\n",pos->first->BLdae.len);
}
头文件
#ifndef __QUEUE_H
#define __QUEUE_H
typedef int typdate;
union LB
{
typdate date;
int len;
};
typedef struct std
{
union LB BLdae;
struct std* NEXT;
}my_queue;
typedef struct
{
my_queue* first;
my_queue* end;
}link_pos;
link_pos*creat_queue();
void insert_LINK(link_pos*,typdate);
typdate out_link(link_pos*);
void BL();
#endif
原文地址:https://blog.csdn.net/2302_77538257/article/details/136242243
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!