Facebook
From Sludgy Hog, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 262
  1. package zadanie3;
  2. import java.util.Scanner;
  3.  
  4. class Stos {
  5.     int[] tab;
  6.     int wierzch;
  7. void init(int size){
  8.         tab = new int[size];
  9.         wierzch = -1;
  10.     }
  11. void destroy(){}
  12. void push(int l){
  13.     tab[++wierzch]=l;
  14. }
  15. void pop(){
  16.     --wierzch;
  17. }
  18. int top(){
  19.     return tab[wierzch];
  20. }
  21. boolean empty(){
  22.     return wierzch== -1;    
  23. }
  24. boolean full(){
  25.     return wierzch== tab.length -1;  
  26. }
  27.        
  28. }
  29. public class Zadanie3 {
  30.  
  31.     public static void main(String[] args) {
  32.         Stos stos1=new Stos();
  33.         Stos stos2=new Stos();
  34.         stos1.init(10);
  35.         stos2.init(10);
  36.         Scanner sk=new Scanner(System.in);
  37.         while(!stos1.full()){
  38.             stos1.push(sk.nextInt());
  39.         }
  40.         System.out.println("Zawartosc stosu: ");
  41.         while (!stos1.empty()){
  42.             System.out.print( " "+stos1.top());
  43.             stos2.push(stos1.top());
  44.             stos1.pop();
  45.         }
  46.         while (!stos2.empty()){
  47.             stos1.push(stos2.top());
  48.             stos2.pop();
  49.         }
  50.         stos1.destroy();
  51.         stos2.destroy();
  52.     }
  53.    
  54. }
  55.