数据结构作业答案(大连理工大学)

作业1. 线性表

数据结构作业答案(大连理工大学)

编程作业:

1. 将顺序表逆置,要求用最少的附加空间。

参考答案

#include <stdio.h> #include <malloc.h> #include <process.h>

#define LIST_INIT_SIZE 100 #define LISTINCREMENT 10

#define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2

typedef int Status; typedef int ElemType;

typedef struct

{ ElemType *elem; int length; int listsize; }SqList;

//创建空顺序表

Status InitList_Sq( SqList &L ) {

L.elem = (ElemType*) malloc (LIST_INIT_SIZE*sizeof(ElemType)); if (!L.elem) exit(OVERFLOW); L.length = 0;

L.listsize = LIST_INIT_SIZE; return OK; }

//顺序表在第i个元素之前插入e

Status sxbcr(SqList &L, int i, ElemType e)

你可能喜欢

  • 离散数学试题答案
  • 数据结构作业
  • 数据结构试题及答案
  • 数据结构习题解析
  • 数据结构习题集

数据结构作业答案(大连理工大学)相关文档

最新文档

返回顶部