Announcement

Collapse
No announcement yet.

Help. giúp mình sửa code này với làm hoài vẫn bị lỗi

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help. giúp mình sửa code này với làm hoài vẫn bị lỗi

    #include<iostream.h>
    struct Node {
    int entry;
    Node *next;
    Node();
    };
    class Stack {
    public:
    Stack();
    ~Stack();
    void PrintAll();
    private:
    Stack& operator =(const Stack &s);
    Node *top;
    void themPhantu(int data);
    void Del();
    int count;
    istream& operator >> (istream& vao,Stack& s);
    ostream& operator << (ostream& ra,Stack& s);
    };
    void Stack :: themPhantu(int item){
    Node* link = new Node();
    link->entry = item;
    link->next =NULL;
    link->next = top;
    top = link;
    count++;
    }
    void Stack :: Del(){

    Node* h;
    while(top!=NULL)
    {
    h= top;
    top = top->next;
    delete h;
    count--;
    }
    }
    void Stack :: PrintAll(){
    while(top!=NULL)
    {
    cout<<top->entry;
    top=top->next;
    }
    }

    Stack :: Stack(){
    top = NULL;
    count = 0;
    }
    Stack::~Stack(){
    Del();
    }

    Stack&Stack :: operator >> (istream& vao,Stack& s)
    {
    int entry;
    vao>>entry;
    s.themPhantu(entry);
    return vao;
    }
    Stack&Stack :: operator <<(istream& ra,Stack& s)
    {
    s.PrintAll(ra);
    return ra;
    }
    Stack&Stack :: operator =(const Stack &s){
    if(top!=NULL)
    Del();
    Node* p = s.top;
    Stack t;
    while(p!=NULL)
    {
    t.themPhantu(p->entry);
    p=p->next;
    }
    return t;
    }
    void main(){
    int data;
    Stack s;
    s.themPhantu(data);
    s.Del();
    }

    Last edited by trangnguyen290493; 24-11-2013, 16:22.

  • #2
    code mà post kiểu này thì next sớm. chưa nhìn đã đau cả mắt :choler:
    Last edited by 10520237; 24-11-2013, 16:57.
    :funny::brick::beauty::what:

    Comment


    • #3
      Originally posted by 10520237 View Post
      code mà post kiểu này thì next sớm. chưa nhìn đã đau cả mắt :choler:

      Comment

      LHQC

      Collapse
      Working...
      X