Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.9 kB
0
Indexable
Never
import java.util.ArrayList;
import java.util.Collections;

public class Stos {

	public static void main(String[] args) {			
		ArrayList<Integer> Stack = Generate();
		
		Push(Stack, 1);
		Push(Stack, 6);
		Push(Stack, 4);
		Push(Stack, 8);
		Push(Stack, 5);
		Push(Stack, 3);
		
		System.out.println("Stos: ");
		Show(Stack);
		
		System.out.println("\n" + "Stos po usunięciu ostatniego elementu: ");
		Pull(Stack);
		Show(Stack);
		
		System.out.println("\n" + "Ilość elementów w stosie: ");
		System.out.println(Count(Stack));
		
		System.out.println("Stos odwrócony: ");
		Reverse(Stack);
		Show(Stack);
		
		
		//Metody
		
	}
	private static ArrayList<Integer> Generate() {
		ArrayList<Integer> Stos = new ArrayList<Integer>();
		return Stos;
		
	}
	private static ArrayList<Integer> Push(ArrayList<Integer> Stos, int Object){
		Stos.add(Object);
		return Stos;
		
	}
	private static ArrayList<Integer> Pull(ArrayList<Integer> Stos){
		Stos.remove(Stos.size()-1);
		return Stos;
	}
	private static int Count(ArrayList<Integer> Stos){
		int dlugosc = Stos.size();
		return dlugosc;
	}
	private static void Show(ArrayList<Integer> Stos){
		for(int i = 0 ; i < Stos.size(); i++) {
		System.out.print(Stos.get(i) + ", ");
		}
	}
	private static ArrayList<Integer> Reverse(ArrayList<Integer> Stos){
		Collections.reverse(Stos);
		return Stos;
		}
}




======================================================================



package matura;

import java.util.ArrayList;
import java.util.Collections;

public class Kolejka {

	public static void main(String[] args) {
		
		ArrayList <Integer> Kol = Create();
		
		System.out.println("Tworzenie kolejki: ");
		System.out.println(Create());
	
		System.out.println("Pokazuje kolejke po dodaniu elementów: ");
		Que(Kol,1);
		Que(Kol,3);
		Que(Kol,8);
		Que(Kol,2);
		Que(Kol,19);
		Que(Kol,12);
		Show(Kol);
		System.out.println();
		
		System.out.println("Zdejmuje pierwszy element z kolejki: ");
		System.out.println(Deque(Kol));

		System.out.println("Ilość elementów w kolejce: ");
		System.out.println(Count(Kol));
		
		System.out.println("Odwrócona kolejka: ");
		System.out.println(Reverse(Kol));
		
	}
	
	private static ArrayList <Integer> Create () {
	
		ArrayList <Integer> Kol = new ArrayList <Integer>();
		return Kol;
	}
	
	private static ArrayList <Integer> Que (ArrayList <Integer> Kol, int Object ) {
		Kol.add(Object);
		return Kol;
	}
	
	private static ArrayList <Integer> Deque (ArrayList <Integer> Kol) {
		Kol.remove(0);
		return Kol;
	}
	
	private static int Count (ArrayList <Integer> Kol) {
		int size = Kol.size();
		return size;
	}
	
	private static void Show (ArrayList <Integer> Kol) {
		for(int i = 0; i < Kol.size(); i++) {
			System.out.print(Kol.get(i) + ", ");
		}
	}
	
	private static ArrayList <Integer> Reverse (ArrayList <Integer> Kol) {
		Collections.reverse(Kol);
		return Kol;
	}

}