-
棧進制轉換進階查看全部
-
初步進制轉換查看全部
-
棧實例化對象測試棧方法查看全部
-
棧的遍歷查看全部
-
出棧,入棧函數查看全部
-
清空棧的函數和求棧長的函數查看全部
-
棧判空,判滿函數查看全部
-
///////////////查看全部
-
////查看全部
-
16進制兼容查看全部
-
棧的一般具有的函數查看全部
-
我的棧 (續): void push(const elemtype &c) { if (isfull()) { cout << "滿了"; // throw .. } node *p = new node(c); top->next = p; p->last = top; top = p; ++size; } elemtype pop() { if (isempty()) { cout << "空了"; // theow .. } elemtype x = top->data; node *p = top; top = p->last; top->next = NULL; delete p; --size; return x; } // 遍歷函數,默認從棧底到棧頂 void traverse(bool isfrombottom = true) { node *p; if (isfrombottom) { p = base->next; while (p) { cout << p->data; p = p->next; } cout<<endl; } else { p = top; while (p != base) { cout << p->data; p = p->last; } cout<<endl; } } int lenth() { return size; } void clearStack() { node *p = base->next,*q; while (p) { q = p; p = p->next; delete q; } top = base; size = 0; base->next = NULL; } };查看全部
-
#include<iostream> using namespace std; #define elemtype char struct node { elemtype data; node *last; node *next; // 新定義的結點的默認構造函數 node(const elemtype data = 0,node *last = NULL,node *next = NULL) { this->data = data; this->last = last; this->next = next; } ~node() { data = 0; last = next = NULL; } }; class stack{ private: node *base; //棧底 node *top; //棧頂 int size; //棧的實際大小 public: stack() { // 申請一個哨兵結點作為棧底,哨兵的data沒有意義 // 如果申請物理空間失敗,拋出異常 if (!(base = new node())) { cout << "內存不足!"; // throw ... } top = base; size = 0; } ~stack() { node *p=base,*q=NULL; while(p) { q = p; p = p->next; delete q; } } bool isfull() { // 嘗試申請一個node,如果可以申請說明未滿 node *p=new node; if (!p) { return true; } else { delete p; return false; } } bool isempty() { return !size; // 也可以寫成 return top == base; }查看全部
-
轉化16進制的時候 來自慕網的用戶 code16 的提示: 直接把棧的數據類型改成char,然后push進去的是num里面的對應,這樣豈不是更好查看全部
-
棧的應用,講的很透徹,另有事例配合說明。查看全部
舉報
0/150
提交
取消