第三周作业
作业题目1:
程序运行结果截图,需测试各种情况。写出测试过程中遇到的主要问题及所采用的解决措施。
运行结果截图:
主要问题:指针的&和*用法不清楚
解决办法:多次进行调试,最终尝试得到结果
代码:
gloabledef.h
#pragma once
#include<string.h>
#include<ctype.h>
#include<malloc.h> /* malloc()等 */
#include<limits.h> /* INT_MAX等 */
#include<stdio.h> /* EOF(=^Z或F6),NULL */
#include<stdlib.h> /* atoi() */
#include<io.h> /* eof() */
#include<math.h> /* floor(),ceil(),abs() */
#include<process.h> /* exit() */
#define OK 1
#define ERROR 0
//#define OVERFLOW -2
#define INITSIZE 100 //顺序表可能达到的最大长度
#define TRUE 1
#define FALSE 0
typedef int Status; //Status 是函数返回值类型,其值是函数结果状态代码。
typedef int ElemType; //ElemType 为可定义的数据类型,此设为int类型
Sqlist.h
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "gloabledef.h"
typedef struct
{
ElemType* data;/*存储空间的基地址*/
int length; /*表的长度(已存入的元素个数)*/
int listsize; /*当前存储空间的容量(能够存入的元素个数)*/
}sqlist;
int InitList(sqlist* L);
int GetLen(sqlist* L);
int GetElem(sqlist* L, int i, ElemType* e);
int Locate(sqlist* L, ElemType x);
void ClearList(sqlist* L);
int Insert(sqlist* L, int i, ElemType item);
void againMalloc(sqlist* L);
int DeleteElem(sqlist* L, int i);
void SqlistTest();
void OutputList(sqlist L);
void CreateSqlist(sqlist* L);
int m;
Sqlist.c
#include "Sqlist.h"
int InitList(sqlist* L)
{
/* 存储空间初始化 */
L->data = malloc(sizeof(ElemType) * INITSIZE);//补全代码,申请INITSIZE大小空间代码
if (!L->data) {
printf("动态存储分配失败!\n");
return FALSE; /*执行此函数则中止程序运行*/
}
L->length = 0; /* 长度为0 */
L->listsize = INITSIZE; /* 当前存储容量初始化 */
return TRUE;
}
int Ge