Friday, 2024-04-26, 4:38 AM
Logged in as Guest | Group "Guests"Welcome Guest | RSS

Love Makes The World Go Round

Site Menu
Tag Board
Site Working Days

File Catalog

Main » Files » Codes » Data Structure

数组的顺序表示和实现
[ Download from this server (5.8 Kb) ] 2011-12-08, 11:34 PM
/*
* Copyright TES@NPU
* All rights reserved.
*
* FileName: Array.h
* Version: 1.5
* Updated @ Dec. 8 2011
* Updated @ Dec. 1 2011
* Finished @ Dec. 1 2011
 */

#include <string.h>
#include <ctype.h>
#include <malloc.h>  //mallc() and so on
#include <limits.h>  //INT_MAX and so on
#include <stdio.h>  //EOF(=^Z or F6), NULL
#include <stdlib.h>  //atoi()
#include <io.h>  //eof()
#include <math.h>  //floor(), ceil(), abs()
#include <process.h>  //exit()
#include <iostream>  //cout, cin
#include <stdarg.h>  // 标准头文件,va_start va_arg va_end

using namespace std;

// Codes for the result of functions
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
// #define OVERFLOW -2 for there was the definition in file "math.h" so it could be omitted

/*
数组维数
 */
#define MAX_ARRAY_DIM 8

typedef int Status;  // Status是函数类型, 其值是函数结果状态代码,如OK等
typedef int Boolean;  // Boolean是布尔类型,其值是TRUE或FALSE
typedef int ElemType;  // ElemType定义为整型,学习使用,工程中可修改。

/*
数组的顺序存储结构
 */
struct Array
{
ElemType *base;  // 数组元素基址,由InitArray分配
int dim;  // 数组维数
int *bounds;  // 数组维界基址,由InitArray分配
int *constants;  // 数组映象函数常量基址,由InitArray分配
};

/* 基本操作函数的声明部分 */
Status InitArray(Array &A, int dim, ...);
Status DestroyArray(Array &A);
Status LocateArray(Array A, va_list ap, int &off);
Status Value(ElemType &e, Array A, ...);
Status Assign(Array &A, ElemType e, ...);


/*
----------
Output in VC++2010:
----------
A.bounds=3 4 2
A.constants=8 2 1
3页4行2列矩阵元素如下:
A[0][0][0]= 0 A[0][0][1]= 1
A[0][1][0]=10 A[0][1][1]=11
A[0][2][0]=20 A[0][2][1]=21
A[0][3][0]=30 A[0][3][1]=31

A[1][0][0]=100 A[1][0][1]=101
A[1][1][0]=110 A[1][1][1]=111
A[1][2][0]=120 A[1][2][1]=121
A[1][3][0]=130 A[1][3][1]=131

A[2][0][0]=200 A[2][0][1]=201
A[2][1][0]=210 A[2][1][1]=211
A[2][2][0]=220 A[2][2][1]=221
A[2][3][0]=230 A[2][3][1]=231

A.base=
   0   1  10  11  20  21  30  31
 100 101 110 111 120 121 130 131
 200 201 210 211 220 221 230 231

DestroyArray Succeeded!
请按任意键继续. . .
 */

/*
调试心得:
在多次单步调试之后,觉得是不是数组
的初始化除了问题----因为采用的是线性的数组结构,
然而忽然之间却可以将内存地址的偏移走得很远很远...
----
学习的路还长着哩。
 */



Category: Data Structure | Added by: tes1991 | Tags: array, Sequence, Data Sturcture
Views: 865 | Downloads: 222 | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Tags...
Tencent
Statistics

Total online: 1
Guests: 1
Users: 0

Copyright MyCorp © 2024