0.棧的建立及標頭檔案宣告
#include#includestruct stack
;struct stack* init_stack(struct stack*);
struct stack* push_stack(struct stack*, int);
int pop_stack(struct stack*, int *);
int stack_top(struct stack*, int *);
int count_stack(struct stack *);
void disp_stack(struct stack*);
void destroy_stack(struct stack *head);
1.初始化棧
//init_stack
struct stack* init_stack(struct stack*head)
2.入棧
//push_stack
struct stack* push_stack(struct stack*head, int x)
3.出棧
//pop_stack
int pop_stack(struct stack*head, int *d)
head->next = p->next;
*d = p->data;
free(p);
printf("退棧的數為%5d\n", *d);
}
4.取棧頂元素
int stack_top(struct stack*head, int *num)
*num = p->data;
printf("棧頂元素為%5d\n", *num);
return 1;
}
5.計算棧的元素個數
int count_stack(struct stack *head)
return k;
}
6.顯示棧
void disp_stack(struct stack*head)
else }
printf("\n");
}
7.銷毀棧
void destroy_stack(struct stack *head)
printf("刪除成功");
}
8.測試程式(main)
鏈棧 資料結構 c語言
這是棧的結構 進棧示意 出棧示意 這是乙個鏈棧,注意與順序棧的區分 include stdio.h include stdlib.h define maxsize 100 typedef struct snode link void menu void link initialize void 初始...
C資料結構 鏈棧
鏈棧的設計依賴於筆者之前設計的鍊錶,詳情請看 c資料結構 線性表之單鏈表 ifndef linkedstack h define linkedstack h include linkedlist.h typedef linked list linked stack 建立鍊錶棧 return link...
C 資料結構 鏈棧
public class linkstacknode 節點指標 public linkstacknode next public linkstacknode t d 鏈棧 public class linkstack 總長度 public int count 入棧 public void push ...