鏈棧的初始化

2021-07-11 02:18:01 字數 1370 閱讀 8407

#include #include using namespace std;

template class linkedstack; //類宣告

template //全域性的operator<<、>>函式都要在類定義前宣告

istream& operator>>(istream &is,linkedstack&s);

template ostream& operator<<(ostream &os,linkedstack&s);

template struct node;

template class linkedstack

int getsize()const;

void makeempty();

friend istream& operator>> <>(istream &is,linkedstack&s); //模板函式做友元要顯式的宣告模板形參,

//如果<>內空就是把當前類的模板引數傳進來用.

friend ostream& operator<< <>(ostream &os,linkedstack&s); //<>不能省略

private:

node*top; //棧頂指標

};template istream& operator>>(istream &is,linkedstack&s)

return is;

}template ostream& operator<<(ostream &os,linkedstack&s) //過載《運算子

return os;

}int main()

template void linkedstack::push(const t&x) //插入元素,插在頭結點*top與開始結點之間

template t linkedstack::pop() //退棧並得到棧頂元素

template t linkedstack::gettop() //得到棧頂元素

template int linkedstack::getsize()const //得到鏈式棧的長度

return n;

}template void linkedstack::makeempty()

top->next=null;

return ;

}

鏈棧的初始化,建立,插入,查詢,刪除。

鏈棧的初始化,建立,插入,查詢,刪除。author wang yong date 2010.8.19 include include typedef intelemtype 定義鏈棧的結構型別 typedef struct stacknode stacknode,linkstack 鏈棧的初始化 l...

鏈棧的初始化,建立,插入,查詢,刪除。

鏈棧的初始化,建立,插入,查詢,刪除。author wang yong date 2010.8.19 include include typedef intelemtype 定義鏈棧的結構型別 typedef struct stacknode stacknode,linkstack 鏈棧的初始化 l...

順序棧和鏈棧的初始化插入和刪除

棧分為順序棧和鏈棧,它們的特點分別如下 順序棧 用一維陣列s m 來表達,top代表棧頂,當棧是空的,top 1,當棧是滿的top m 1。順序棧的定義 typedef int elemtype typedef struct sqstack sqstack 進棧 elemtype push elem...