Advertisement
Guest User

AiSD1_1

a guest
Sep 18th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3. namespace AiSD1
  4. {
  5.     class Program
  6.     {
  7.         public class Stec
  8.         {
  9.             int[] S = new int[100];
  10.             int top = 0;
  11.             public void PUSH(int x)
  12.             {
  13.                 S[top] = x;
  14.                 top++;
  15.             }
  16.             public bool POP()
  17.             {
  18.                 if (!ISEMPTY())
  19.                 {
  20.                     S[top - 1] = -1;
  21.                     return true;
  22.                 }
  23.                 else
  24.                 {
  25.                     return false;
  26.                 }
  27.             }
  28.             public bool ISEMPTY()
  29.             {
  30.                 if (top == 0)
  31.                 {
  32.                     return true;
  33.                 }
  34.                 else
  35.                 {
  36.                     return false;
  37.                 }
  38.             }
  39.             public void CLAER()
  40.             {
  41.                 int n = 0;
  42.                 while (S[n] != -1)
  43.                 {
  44.                     n++;
  45.                     S[n] = -1;
  46.                 }
  47.             }
  48.             public int TOP()
  49.             {
  50.                 return S[top - 1];
  51.             }
  52.         }
  53.        
  54.         static void Main(string[] args)
  55.         {
  56.             Stec S = new Stec();
  57.             S.PUSH(10);
  58.             S.PUSH(10);
  59.             S.PUSH(10);
  60.             S.PUSH(10);
  61.             S.POP();
  62.             Console.WriteLine(S.TOP());
  63.             S.CLAER();
  64.             Console.WriteLine(S.ISEMPTY());
  65.             Console.WriteLine("Hello World!");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement