搜档网
当前位置:搜档网 › 数据结构结构体定义

数据结构结构体定义

-------------------------线性表----------------------
typedef struct
{
char name[20];//注意如果应用指针的形式,在初始化每个结点时一定要先为结点中的每个变量开辟内存空间
char sex;
char addr[100];
unsigned int age;
char phonenum[20];
}node;//结点描述
typedef struct
{
node *p;
int length;//当前顺序表长度
int listsize;//当前分配的线性表长度
}list;//线性表描述
list L;//定义一个线性表

------------------------------------------------------


----------------------链表-----------------------------
typedef struct
{
int num;
}node;
typedef struct LIST
{
node data;
struct LIST *next;
}list,*slist;
int CreatList(slist &head)//此处应为只针对的引用
{
head=(list *)malloc(sizeof(list));
if(!head)
return ERROR;
head->next=NULL;
return OK;
}
---------------------------------------------------------------


-----------------------栈------------------------------
//---------利用栈结构实现数制之间的转换------//
typedef struct
{
int num;
}node;
typedef struct
{
node *base;
node *top;
int stacksize;
}stack;//顺序栈结构定义

//----------链栈描述---------//
typedef struct Node
{
int num;
struct Node *next;
}node;
typedef struct
{
Node *top;
Node *base;
}stack;
---------------------------------------------------------------



--------------------队列---------------------------------------
//------链队列的描述及操作-------//
typedef struct Node
{
int a;
struct Node *next;
}Qnode,*QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;

//-------------循环队列-----------//
typedef struct node
{
int data;
struct node *next;
}node;
typedef struct queue
{
node *base;
int front;
int rear;
}Queue;
int tag;
-----------------------------------------------------------------


--------------------------串-------------------------------------
//-----------串:堆分配存储形式的一些操作------------------//
typedef struct string
{
char *ch;
int length;
}sstring;
-----------------------------------------------------------------


———————----------------数组-----------------------------------------
-----------矩阵转置的经典算法---------
for(i=0;ifor(j=0;jb[j][i]=a[i][j];
时间复杂度为O(row*col),每个元素都要存储,相对于稀疏矩阵来说比较浪费存储空间。
----------矩阵转置---利用三元组实现---------
#define MAX 12500//假设一个稀疏矩阵最多有12500个非零元
typedef struct
{
int i,j;//i,j用于存储矩阵中元素的行、列下标
int num;//num为矩阵中非零元的值
}Triple;//定义一个三元组
typedef struct
{
Triple data[MAX+1];
int mu,nu,tu;//mu,nu非别表示一个稀疏矩阵的行数和列数
//tu表示该稀疏矩阵的非零元个数
}TSMatrix;
------

-----------------------------------------------------------------



---------------十字链表------------------------------------------------
//定义
typedef struct OLNode{
int i,j;//行列下标
int e;
struct OLNode *right,*dowm;
}OLNode;
typedef struct ListMatrix{
OLNode *rhead,*chead;
int mu,nu,tu;//行数、列数、非零元个数
}ListMatrix;
-----------------------------------------------------------------------


--------------------广义表---------------------------------------------
------------广义表的构造及递归遍历-----------
//广义表的定义用到串的一些操作,上述已有串的定义在此不再叙述。
typedef enum{ATOM,LIST}ElemTag;
typedef struct GLNode{
ElemTag tag;
union{
char atom;
struct{struct GLNode *hp,*tp;}ptr;
};//若atom占用内存则表明为原子结点,否则ptr占用内存为表结点
}*Glist;//广义表结点结构的定义
------------------------------------------------------------------------


------------------树----------------------------------------------------
//--------二叉树----------------//
typedef struct BTree{
int data;
struct BTree *lchild,*rchild;
}BiTNode,*BiTree;




相关主题