File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11package Java .Queu ;
22import java .util .*;
33public class Question {
4+ public static void reverse (Queue <Integer > q ){
5+ Stack <Integer > s = new Stack <>();
6+
7+ while (!q .isEmpty ()){
8+ s .push (q .remove ());
9+ }
10+ while (!s .isEmpty ()){
11+ q .add (s .pop ());
12+ }
13+ }
414 public static void printNonRepating (String str ){
515 int freq [] = new int [26 ];
616 Queue <Character > q = new LinkedList <>();
@@ -25,5 +35,19 @@ public static void printNonRepating(String str){
2535 public static void main (String args []){
2636 String str = "aabccxb" ;
2737 printNonRepating (str );
38+
39+ Queue <Integer > q = new LinkedList <>();
40+ q .add (1 );
41+ q .add (2 );
42+ q .add (3 );
43+ q .add (4 );
44+ q .add (5 );
45+
46+ reverse (q );
47+ while (!q .isEmpty ()) {
48+ System .out .print (q .remove ()+ " " );
49+ }
50+ System .out .println ();
51+
2852 }
2953}
You can’t perform that action at this time.
0 commit comments