Truyen2U.Net quay lại rồi đây! Các bạn truy cập Truyen2U.Com. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

Stack

//Bai_STACK

#include <conio.h>

#include <stdio.h>

#include <iostream.h>

#define max 100

class stack

{

  private:

    int top,a[max];

  public:

    stack()

    {

      top=0;

    }

    int empty()

    {

       if (top==0)

        return 1;

       return 0;

    }

    int full(int n)

    {

       if (top==n)

          return 1;

       return 0;

    }

    void push(int n)

    {

       int gt;

       if (!full(n))

       {

       cout<<"Nhap vao gia tri can day vao stack: ";

       cin>>gt;

       top++;

       a[top]=gt;

       }

       else

        cout<<"Stack day";

    }

    void pop()

    {

       if (empty())

          cout<<"Stack rong";

       else

      /* int gt=a[top];

       cout<<"Gia tri lay ra la: "<<gt;*/

       {cout<<a[top];

       top--;}

    }

};

int main()

{

   stack b;int n;

   cout<<"Nhap vao dinh cua stack: ";cin>>n;

   for (int i=1;i<=n+1;i++)

    b.push(n);

   for (i=1;i<=n;i++)

   b.pop();

   getch();

   return 0;

}

Bạn đang đọc truyện trên: Truyen2U.Com

Tags: