採用鍊錶來模擬棧的出入棧操作,將頭結點指向的位置設定為棧頂,這樣對於插入刪除來說效率更高。
#define _crt_secure_no_warnings
#include
#include
#include
//棧的節點結構體
struct stacknode
;//棧表
struct stacklist
;typedef
void
* stack;
//棧的初始化
stack init_stacklist()
//入棧
void
push_stack
(stack stack,
void
* data)
//出棧
void
pop_stack
(stack stack)
//返回棧頂元素
void
*get_top_value
(stack stack)
//返回棧個數
intsize_stack
(stack stack)
//棧的判空
intisempty
(stack stack)
//銷毀棧
void
destroy_stack
(stack stack)
//測試
typedef
struct person person;
void
test01()
; person p2 =
; person p3 =
; person p4 =
;//初始化得到鏈棧
stack* mystack =
init_stacklist()
;//入棧
push_stack
(mystack,
&p1)
;push_stack
(mystack,
&p2)
;push_stack
(mystack,
&p3)
;push_stack
(mystack,
&p4)
;while
(isempty
(mystack)==0
)printf
("棧裡的元素還剩%d\n"
,size_stack
(mystack));
destroy_stack
(mystack)
; mystack =
null;}
intmain()
棧元素入棧出棧操作(C)
元素入棧時,會先將棧壓入,top指標再向上加一。c語言如何實現呢,下面是入棧的 片段 typedef struct node sqstack void push sqstack s,int elem 入棧 s top elem,s本為指向node結構的乙個指標,本來對普通結構體指標賦值或者使用用 s...
棧的入棧,出棧,擴容,獲取長度等操作
建立stack.h pragma once 棧 一種訪問受限的線性表,只能在一端進行資料操作,能操作 順序棧,棧頂設計在順序表的表尾處,因為順序表尾插和尾刪都是o 1 define init size 10 typedef struct seqstack seqstack,pseqstack 初始化...
c語言實現棧與鏈棧
include include define max 100 陣列最大空間 typedef struct stack intisfull stack l intisempty stack l void initialize stack l 初始化順序棧 char top stack l 返回棧頂元素...