72 lines
1.2 KiB
C
72 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
typedef struct {
|
|
int max; //列表最大长度
|
|
int length; //列表现在的长度
|
|
int *start; //内存地址起始位置
|
|
int front; //列表起始索引
|
|
int end; //列表结束索引
|
|
|
|
}queue;
|
|
|
|
|
|
int main(){
|
|
queue q;
|
|
printf("输入整个列表长度");
|
|
int length;
|
|
scanf("%d",&length);
|
|
int b;
|
|
printf("接下来依次输入放进列表的东西");
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
/* code */
|
|
scanf("%d",&b);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
int q_init(queue *q,int length){ //就是普通的初始化。要给他什么参数呢?首先就是queue的地址,然后是一个初始长度。然后初始化全0就行了。
|
|
q->start=malloc(length*sizeof(int));
|
|
q->max=length;
|
|
q->front=0;
|
|
q->end=0;
|
|
q->max=0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int q_add(queue *q,int num){ //最后边加上元素
|
|
if(q->length==q->max){ //容量不够了的自动扩容
|
|
q->max+=5;
|
|
q->start=realloc(q->start,q->max*sizeof(int));
|
|
}
|
|
q->start[q->end]=num;
|
|
q->end++;
|
|
q->length++;
|
|
}
|
|
|
|
int q_addpro(){ //任意地方加上元素,要进去一个索引编号和数值
|
|
|
|
|
|
}
|
|
|
|
int q_reduce(){ //最前面拿走元素
|
|
|
|
|
|
}
|
|
|
|
int q_reducepro(){ //任意地方拿走元素,也是索引号+数值
|
|
|
|
|
|
} |