source\TraceTableUnit
/******************************************************************************
******************************************************************************
File Name :
Version :
Author :
Created : 2009/6/1
Last Modified :
Description :
Function List :
History :
1.Date : 2009/6/1
Author :
Modification: Created file
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
// 数据表规格定义
#define MAX_ROW_LENGTH 9
#define MAX_COLUMN_LENGTH 9
// 数据表节点位置信息定义
typedef struct Table_Node
{
int iRowNo; //行号, 从0开始编号
int iColumnNo; //列号, 从0开始编号
}TABLE_NODE;
// 节点轨迹变化链表信息
typedef struct Orbit_List
{
TABLE_NODE node; //节点位置信息
struct Orbit_List *pNext;
}ORBIT_LIST;
/*****************************************************************************
Description : 初始化数据表.
Prototype : int InitTable (int iRowLength, int iColumnLength)
Parameters : int iRowLenth - 数据表的行数
int iColumnLenth - 数据表的列数
Return Value : int - 初始化成功返回0, 失败返回-1
*****************************************************************************/
TABLE_NODE NODE[MAX_ROW_LENGTH][MAX_COLUMN_LENGTH] = {} ;
// 数据表信息
typedef struct table
{
TABLE_NODE node; //节点位置信息
struct table *Next;
}TABLE;
int g_reinit_flag = 0;
int InitTable(int iRowLength, int iColumnLength)
{
// 请在这里实现功能
if(iRowLength > MAX_ROW_LENGTH || iRowLength <= 0){
printf("the row is unnomal !");
return -1;
}
if(iColumnLength > MAX_COLUMN_LENGTH || iColumnLength <= 0 ){
printf("the colum is unnomal !");
return -1;
}
if(g_reinit_flag)
return -1;
for(int i = 0;i < iRowLength;i++ )
for(int j = 0;j < iColumnLength;j++){
NODE[i][j].iRowNo = i;
NODE[i][j].iColumnNo = j;
}
g_reinit_flag = 1;
return 0;
}
/*****************************************************************************
Description : 销毁数据表.
Prototype : void DestroyTable (void)
Parameters : 无
Return Value : 无
*****************************************************************************/
void DestroyTable (void)
{
// 请在这里实现功能
for(int i = 0;i < MAX_ROW_LENGTH;i++ )
for(int j = 0;j < MAX_COLUMN_LENGTH;j++){
NODE[i][j].iRowNo = 0;
NODE[i][j].iColumnNo = 0;
}
g_reinit_flag = 0;
return;
}
/*****************************************************************************
Description : 交换数据表的两个指定单元.
Prototype : int SwapUnit (TABLE_NODE stNode1, TABLE_NODE stNode2)
Parameters : TABLE_NODE stNode1 - 指定交换的节点1
TABLE_NODE stNode2 - 指定交换的节点2
Return Value : int - 交换成功返回0, 失败返回-1
*****************************************************************************/
int SwapUnit (TABLE_NODE stNode1, TABLE_NODE stNode2)
{
// 请在这里实现功能
return 0;
}
/*****************************************************************************
Description : 在数据表中插入一列
Prototype : int InsertColumnToTable (int iColumnNo)
Parameters : iColumnNo - 指定插入的列号
Return Value : 插入成功返回0, 失败返回-1
*****************************************************************************/
int InsertColumnToTable(int iColumnNo)
{
// 请在这里实现功能
return 0;
}
/*****************************************************************************
Description : 在数据表中插入一行
Prototype : int InsertRowToTable(int iRowNo)
Parameters : iColumnNo - 指定插入的行号
Return Value : 插入成功返回0, 失败返回-1
*****************************************************************************/
int InsertRowToTable(int iRowNo)
{
// 请在这里实现功能
return 0;
}
/*******************************************************************************************************
Description : 查询数据表中某个节点的位置变化轨迹.
Prototype : int QueryOrbitOfUnitData(TABLE_NODE stNode, ORBIT_LIST** ppOrbit)
Parameters : TABLE_NODE stNode - 指定查询的原表格中的节点
ORBIT_LIST** ppOrbit - 节点变化轨迹链表
此链表内存由本函数负责申请,调用者调用FreeOrbitOfUnitData进行释放
Return Value : 查询成功返回0, 失败返回-1
*********************************************************************************************************/
int QueryOrbitOfUnitData(TABLE_NODE stNode, ORBIT_LIST** ppOrbit)
{
// 请在这里实现功能
//没分配内存,链表指针为空,请自行修改
*ppOrbit = NULL;
return 0;
}
/*****************************************************************************
Description : 释放查询时返回的节点位置变化轨迹链表的内存.
Prototype : int FreeOrbitOfUnitData(void* pOrbit)
Parameters : void* pOrbit - 释放的链表头指针
Return Value : 无
*****************************************************************************/
void FreeOrbitOfUnitData(void* pOrbit)
{
// 请在这里实现功能
return;
}
843

被折叠的 条评论
为什么被折叠?



