Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Queue<Integer> qint = new LinkedList<Integer>(); //// ta3rifkrdny queue bo integer
- Queue<String> qstring = new LinkedList<String>();//// ta3rifkrdny queue bo string
- /// tekrdny data bo queue
- qint.add(1);
- qint.add(2);
- qstring.add("a");
- qstring.add("b");
- /// serkrdny yakam datay naw queue
- System.out.println(qint.peek());
- System.out.println(qstring.peek());
- /// zanini qabaray naw queue
- System.out.println(qint.size());
- System.out.println(qstring.size());
- /// check krdn boy bzanin queue batala yan na
- System.out.println(qint.isEmpty());
- System.out.println(qstring.isEmpty());
- /// darkrdny data la queue
- System.out.println(qint.remove());
- System.out.println(qstring.remove());
- /// pechawana krdnaway datay naw queue ba stack
- /// yan chonety bakar henany stack w queue pekawa
- Queue<Integer> q = new LinkedList<Integer>();
- Stack<Integer> s = new Stack<Integer>();
- q.add(1);
- q.add(2);
- q.add(3);
- q.add(4);
- while (!q.isEmpty()) { //// sarata zhmarakan axayna naw stack
- s.push(q.remove());
- }
- while (!s.isEmpty()) { /// dway ayxaynawa naw queue ama wa akat pechawana betawa
- q.add(s.pop());
- }
- System.out.println(q);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement