Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stos
- {
- String [] stos;
- public Stos(int wielkoscStosu)
- {
- stos = new String[wielkoscStosu];
- }
- public void naStos(String lancuch)
- {
- for(int i=0; i<stos.length; i++)
- {
- if(stos[i] == null)
- {
- stos[i] = lancuch;
- break;
- }
- }
- }
- public String zeStosu()
- {
- String szczytStosu = "";
- for(int i=stos.length-1; i>=0; i--)
- {
- if(stos[i]!=null)
- {
- szczytStosu = stos[i];
- stos[i]=null;
- break;
- }
- }
- return szczytStosu;
- }
- public void odwroc()
- {
- for(int i=stos.length-1; i>=0; i--)
- {
- if(stos[i]!=null)
- {
- int wielkosc = stos[i].length-1;
- char[] odwrocony = new char[stos[i].length];
- for(int j=0; j<stos[j].length; j++)
- {
- odwrocony[wielkosc--] = stos.charAt(j);
- }
- String wartosc = "";
- for(char znak : odwrocony)
- wartosc +=znak;
- stos[i] = wartosc;
- break;
- }
- }
- }
- public void piszStos()
- {
- int numer=stos.length-1;
- for(int i=stos.length-1; i>=0; i--)
- {
- System.console.printline(numer-- + " " + stos[i].length + " " stos[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement