通讯录(一)

一、Contact.h

1.1.作用 :定义个人信息结构体 peoInfo 和常量。
1.2.代码:

代码如下:

#pragma once

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<assert.h>

#define MAX_NAME 20

#define MAX_PHONE 20

#define MAX_GENDER 10

#define MAX_ADDR 20

typedef struct peoInfo{

char nameMAX_NAME;

int age;

char genderMAX_GENDER;

char addrMAX_ADDR;

char phoneMAX_PHONE;

}peoInfo;

struct SeqList;

二、SeqList.h

2.1.作用 :定义顺序表结构,设置数据类型为 peoInfo,并将顺序表别名为 Contact。
2.2.代码

代码如下:

#pragma once

#include"Contact.h"

typedef peoInfo SLDataType;

typedef struct SeqList {

SLDataType* a;

int size;

int capacity;

}SL;
typedef struct SeqList Contact; // 前置声明:告诉编译器有一个叫 SeqList 的结构体,因为 Contact.h 需要被 SeqList.h 包含,而 SeqList 的定义在 SeqList.h 中 为了避免循环依赖,这里只声明,具体定义在 SeqList.h

void SLCheckCapacity(SL* sl);

void SLprint(SL* sl);

void SLInit(SL* sl);

void SLPushFront(SL* sl, SLDataType x);

void SLPushBack(SL* sl, SLDataType x);

void SLInsert(SL* sl, int pos, SLDataType x);

void SLRemoveAll(SL* sl, SLDataType x);

void SLPopFront(SL* sl);

void SLPopBack(SL* sl);

void SLErase(SL* sl, int pos);

//查找元素

int SLFind(SL* sl, SLDataType x);

//修改指定位置的数据

void SLModify(SL* sl, int pos, SLDataType);

三、3-23.c

3.1.作用:实现顺序表的底层增删查改逻辑。
3.2.代码

代码如下:

// 打印单个

void PrintOne(const peoInfo* p) {

printf("%-10s %3d %-6s %-15s %-20s\n", p->name, p->age, p->gender, p->tel, p->addr);

}

// 打印所有

void SLPrint(SL* sl) {

assert(sl);

if (sl->size == 0) {

printf("通讯录为空。\n");

return;

}

printf("\n%-10s %-5s %-6s %-15s %-20s\n", "姓名", "年龄", "性别", "电话", "地址");

printf("------------------------------------------------------------\n");

for (int i = 0; i < sl->size; i++) {

PrintOne(&sl->ai);

}

printf("------------------------------------------------------------\n");

}

相关推荐
IT空门:门主4 小时前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线
java·学习
Shadow(⊙o⊙)5 小时前
一年间学习的总结与成长记录——记录自己的18岁
学习
不脱发的程序猿5 小时前
详解UDS CAN诊断:CommunicationControl Service(SID:0x28)
c语言·can·uds·汽车诊断·iso-tp
 梦晓天明6 小时前
1.Spring学习笔记_IOC入门案例
笔记·学习·spring
炸膛坦客7 小时前
单片机/C/C++八股:(三十七)指针数组 和 数组指针
c语言·开发语言·c++
sharemylove13 小时前
Java 异常处理 学习笔记
java·开发语言·经验分享·笔记·学习
Navigator_Z13 小时前
LeetCode //C - 1320. Minimum Distance to Type a Word Using Two Fingers
c语言·算法·leetcode
发疯的技术鼠14 小时前
第21篇-联合和枚举
c语言
sharemylove14 小时前
Java 常用类 学习笔记
java·开发语言·经验分享·笔记·学习
23图1 天前
C 语言开散列表(拉链法)拆解:链挂得没错,key=-1 会去读 T[-1]
c语言·开发语言·散列表