栈的链表实现 (二)

2014-11-23 21:42:18 · 作者: · 浏览: 14
<

2)stack.cpp


 * stack_1.cpp
 *
 *  Created on: 2013年8月2日
 *    为了能有章泽天这样的女朋友而不断努力。。。。。。
 *    加油。。。fighting。。。。。
 */ 
 
#include   
#include "list_2.h"  
 
using namespace std; 
 
class Stack{ 
    List l; 
public: 
    void push(const T& d){ 
        l.push_front(d); 
    } 
 
    T pop(){ 
 
        T t = l.front(); 
        l.erase(0); 
        return t; 
    } 
 
    const T& top(){ 
 
        return l.front(); 
    } 
 
    bool empty(){ 
 
        return l.empty(); 
    } 
 
    bool full(){ 
 
        return false; 
    } 
 
    void clear(){ 
 
        l.clear(); 
    } 
 
    int size(){ 
 
        return l.size(); 
    } 
}; 
int main(){ 
 
    Stack s; 
    s.push(2); 
    s.push(4); 
    s.push(6); 
    s.push(8); 
    s.push(10); 
 
    while(!s.empty()){ 
        cout<< s.pop()<
#include "list_2.h"

using namespace std;

class Stack{
 List l;
public:
 void push(const T& d){
  l.push_front(d);
 }

 T pop(){

  T t = l.front();
  l.erase(0);
  return t;
 }

 const T& top(){

  return l.front();
 }

 bool empty(){

  return l.empty();
 }

 bool full(){

  return false;
 }

 void clear(){

  l.clear();
 }

 int size(){

  return l.size();
 }
};
int main(){

 Stack s;
 s.push(2);
 s.push(4);
 s.push(6);
 s.push(8);
 s.push(10);

 while(!s.empty()){
  cout<< s.pop()<