初始提交:顺序表结构体、初始化与尾部追加

This commit is contained in:
7840HS_LapTop
2026-09-16 20:11:20 +08:00
commit b0b2caa90e
3 changed files with 108 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
#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(){ //任意地方拿走元素,也是索引号+数值
}