顺序表的头部插入和尾部插入;
顺序表类似于数组;但是顺序表的要求必须是连续的元素;而数组可以是有空隙和间隔的
顺序表的逻辑结构和物理结构完全相同;
使用顺序表来编写通讯录;使各个联系人数据串联在一起;
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
//目前只完成了尾部插入
typedef struct ifo //联络人信息列表
{
char name[5];
int age;
char tel[15];
}ifo;
typedef struct address //通讯录的结构
{
ifo* ifoptr;
int size;
int mix;
}address;
void addressstart(address *ptr) //初始化通讯录,赋给5个容量
{
assert(ptr);
ptr->size = 0;
ptr->ifoptr = (ifo*)calloc(5,sizeof(ifo));
if (ptr->ifoptr == NULL)
{
printf("calloc file\n");
assert(0);
return ;
}
ptr->mix = 5;
}
void pushback(address* ptr,ifo tmp) //尾部插入
{
assert(ptr);
if (ptr->mix == ptr->size)
{
ptr->ifoptr = realloc(ptr->ifoptr, sizeof(ifo) * (ptr->mix + 10));
if (ptr->ifoptr == NULL)
{
printf("reall