鏈式堆疊 c

2021-08-13 15:47:05 字數 599 閱讀 9392

//鏈式堆疊.c

#include

#include

typedef struct node

lsnode;

//初始化

void stackinitiate(lsnode **head)

//非空否

int stacknotempty(lsnode *head)

//入棧

void stackpush(lsnode *head,datatype x)

//出棧

void stackpop(lsnode *head,datatype *x)

else

}//取棧元素

void stacktop(lsnode *head,datatyep *x)

else

}//撤銷

void destroy(lsnode **head)

鏈式堆疊的關鍵是運用 **head, head頭指標的作用與順序堆疊的top相同,都是與頭元素的座標相關。需要注意的點在於初始化時,要對*head操作,所以要傳入*head的位址值**head,同樣,撤銷時也需要對*head操作,傳入**head。head指向頭結點,再指向棧頂元素。

鏈式堆疊實現

ifndef stack linked h define stack linked h include include include using namespace std templatestruct node stack templateclass stack linked templates...

c語言堆疊鏈式儲存結構

include include define error 0 define ok 1 typedef int elementtype typedef int status struct snode typedef struct snode stack 堆疊初始化,建立乙個堆疊的頭結點,指向null ...

鏈式堆疊的實現

include stdlib.h include stdio.h include string.h define true 1 define false 0 typedef structlelemtype typedef struct templstack lstack initstack void...