C語言描述 棧結構

2021-10-24 19:34:07 字數 4022 閱讀 4891

鏈式棧對於棧的使用常常使用陣列結構進行實現,因為棧和順序線性表很大區別就在於棧只用對頂部元素進行增刪操作即可,和順序線性表一旦增刪就要改動很大的特點有了很大優化。

int

isempty

(stack s)

int

isfull

(stack s,

int maxsize)

stack creatstack

(int maxsize)

else

else

}}

void

push

(int x,stack s,

int maxsize)

else

}

void

pop(stack s)

else

}

void

disposestack

(stack s)

}

int

gettop

(stack s)

else

}

#include

#include

#include

using

namespace std;

struct stack

;typedef

struct stack* stack;

stack creatstack

(int maxsize)

;int

isempty

(stack s)

;int

isfull

(stack s,

int maxsize)

;void

makeempty

(stack s)

;void

pop(stack s)

;void

push

(int x,stack s,

int maxsize)

;void

disposestack

(stack s)

;int

gettop

(stack s)

;int

topandpop

(stack s)

;int

main

(void

)stack creatstack

(int maxsize)

else

else}}

intisempty

(stack s)

intisfull

(stack s,

int maxsize)

void

makeempty

(stack s)

void

pop(stack s)

else

}void

push

(int x,stack s,

int maxsize)

else

}void

disposestack

(stack s)

}int

gettop

(stack s)

else

}int

topandpop

(stack s)

else

}

struct stack*

creatstack

(void

)else

}

int

stackemty

(struct stack*s)

else

}

struct node*

push

(struct node* top)

printf

("請輸入學生姓名,成績:");

scanf

("%s%f"

, node->name,

&(node->score));

node->next = top;

top = node;

return top;

}

void

outputstack

(struct stack* s)

printf

("\n");

}

void

gettop

(struct node* top)

struct node*

pop(

struct node* top)

;

void

destroystack

(struct stack* s)

}

#include

#include

#include

struct node

;struct stack

;struct stack*

creatstack

(void);

intstackemty

(struct stack* s)

;struct node*

push

(struct node* top)

;void

outputstack

(struct stack*);

void

gettop

(struct node* top)

;struct node*

pop(

struct node* s)

;void

destroystack

(struct stack*);

intmain

(void

)else

printf

("1、判斷空\n2、壓棧\n3、輸出整個棧\n4、取棧頂頂點\n5、出棧\n6、銷毀棧\n7、退出\n");

while(1

)else

if(ret ==0)

break;}

case2:

case3:

case4:

case5:

else

break;}

case6:

case7:

}}return0;

}struct stack*

creatstack

(void

)else

}int

stackemty

(struct stack* s)

else

}struct node*

push

(struct node* top)

printf

("請輸入學生姓名,成績:");

scanf

("%s%f"

, node->name,

&(node->score));

node->next = top;

top = node;

return top;

}void

outputstack

(struct stack* s)

printf

("\n");

}void

gettop

(struct node* top)

struct node*

pop(

struct node* top)

;void

destroystack

(struct stack* s)

}

資料結構(C語言描述)棧

棧是一種特殊的表,這種表只在表首進行插入和刪除操作。因此,表首對棧來說具有特殊的意義,稱為棧頂。表尾稱為棧底。不含任何元素的棧稱為空棧。假設乙個棧s中的元素為a n a n 1 a 1 則稱a 1 為棧底元素,a n 為棧頂元素。棧中元素按a 1 a 2 a n 的次序進棧。在任何時候,出棧的元素都...

c語言描述 棧的基本操作

一朵花兒開,就有一朵花兒敗,滿山的鮮花,只有 最可愛 include include define maxsize 100 定義最大儲存空間 define stackincrement 10 增加的儲存空間,increment意為 加薪 增值 typedef struct stack 初始化棧 vo...

資料結構 C語言描述 讀書筆記之棧

棧又稱堆疊,它是一種運算受限的線性表,其限制是僅允許在表的一端進行插入和刪除運算。一般把對棧進行運算的一端稱為棧頂,另一端稱為棧底。一,棧的順序儲存 struct stacksq 初始化棧s為空 void initstack struct stacksq s,int ms s maxsize ms ...