#include <stdio.h>
#include <stdlib.h>
#include "./004.funcle.h"
//创建链式链表队列
poslink* queue_like()
{
poslink* ont = (poslink*)malloc(sizeof(poslink));
ont->frunt = (linkequeue*)malloc(sizeof(linkequeue));
if(ont->frunt == NULL)
{
printf("创建失败,链表队列创建失败\n");
return NULL;
}
ont->frunt->text.len = 0;
ont->frunt->next = NULL;
ont->rear = ont->frunt;
return ont;
}
//尾插法插入
void poptext_make(poslink* heald,datatype unte)
{
linkequeue* temp = (linkequeue*)malloc(sizeof(linkequeue));
if(temp == NULL)
{
printf("插入失败,链表插入失败\n");
return;
}
heald->frunt->text.data = unte;
heald->frunt->next = NULL;
temp->next = heald->rear->next;
heald->rear->next = temp;
heald->rear = heald->rear->next;
heald->frunt->text.len++;
return;
}
//头删
void make_poptext(poslink* heald)
{
if(heald->frunt->next == NULL)
{
printf("头删失败\n");
return;
}
datatype tack;
tack = heald->frunt->text.data;
poslink* p = heald->frunt->next;
heald->frunt->next = heald->frunt->next->next;
heald->frunt->text.len--;
free(p);
return;
}
//遍历
void redun_link(poslink *hald)
{
if(hald->frunt->next==NULL)
{
printf("链表为空");
return ;
}
linkequeue*p=hald->frunt->next;
while(p->next!=NULL)
{
p=p->next;
printf("%d ",p->text.data);
}
printf("\n");
printf("长度%d\n",hald->frunt->text.len);
}
头文件
#ifndef __LIANSHI_H__
#define __LIANSHI_H__
typedef int datatype;
union masg
{
datatype data;
int len;
};
typedef struct node
{
union masg text;
struct node* next;
}linkequeue;
typedef struct
{
linkequeue* frunt;
linkequeue* rear;
}poslink;
poslink* queue_like();
void poptext_make(poslink* heald,datatype unte);
void make_poptext(poslink* heald);
void redun_link(poslink*hald);
#endif
#include <stdio.h>
#include "./004.funcle.h"
int main(int argc, const char *argv[])
{
poslink* max = queue_like();
poptext_make(max,500);
make_poptext(max);
redun_link(max);
return 0;
}