#include <stdio.h>
#include <stdlib.h>
#define addSize 5typedef int elemType;
typedef struct
{
int size;
elemType *head;
int length;
} table;void createTable(table *t)
{
scanf("%d", &(t -> size));t -> head = (elemType*)malloc(t -> size * sizeof(elemType));
if (t -> head)
{
t -> length = 0;
while((t -> length) < (t -> size))
{
scanf("%d", &(t -> head[t -> length]));
t -> length++;
}}
else
{
printf("分配空间失败");
exit(0);
}
}void showTable(table t)
{
int i = 0;
while(i < t.length)
{
printf("%d ", t.head[i]);
i++;
}
printf("\n");
}int main()
{
table t;
createTable(&t);showTable(t);
free(t.head);
return 0;
}
创建顺序表
最新推荐文章于 2024-11-10 21:43:58 发布