Advertisement
Nakumas

Stos

Sep 22nd, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. class Stos
  2. {
  3.     String [] stos;
  4.     public Stos(int wielkoscStosu)
  5.     {
  6.         stos = new String[wielkoscStosu];
  7.     }
  8.     public void naStos(String lancuch)
  9.     {
  10.         for(int i=0; i<stos.length; i++)
  11.         {
  12.             if(stos[i] == null)
  13.             {
  14.                 stos[i] = lancuch;
  15.                 break;
  16.             }
  17.         }
  18.     }
  19.     public String zeStosu()
  20.     {
  21.         String szczytStosu = "";
  22.         for(int i=stos.length-1; i>=0; i--)
  23.         {
  24.             if(stos[i]!=null)
  25.             {
  26.                 szczytStosu = stos[i];
  27.                 stos[i]=null;
  28.                 break;
  29.             }
  30.         }
  31.         return szczytStosu;
  32.     }
  33.     public void odwroc()
  34.     {
  35.         for(int i=stos.length-1; i>=0; i--)
  36.         {
  37.             if(stos[i]!=null)
  38.             {
  39.                 int wielkosc = stos[i].length-1;
  40.                 char[] odwrocony = new char[stos[i].length];
  41.                 for(int j=0; j<stos[j].length; j++)
  42.                 {
  43.                     odwrocony[wielkosc--] = stos.charAt(j);
  44.                 }
  45.                 String wartosc = "";
  46.                 for(char znak : odwrocony)
  47.                     wartosc +=znak;
  48.                 stos[i] = wartosc;
  49.                 break;
  50.             }
  51.         }
  52.     }
  53.     public void piszStos()
  54.     {
  55.         int numer=stos.length-1;
  56.         for(int i=stos.length-1; i>=0; i--)
  57.         {
  58.             System.console.printline(numer-- + " " + stos[i].length + " " stos[i]);
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement