Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class lista{
  6.     String val;
  7.     lista st,dr;
  8.     public lista(String val1) {
  9.         val=val1;
  10.        
  11.     }
  12.     public lista() {}
  13. }
  14.  
  15. public class p1 {
  16.  
  17.     static void citire(lista x) throws IOException{
  18.    
  19.     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  20.     String text=br.readLine();
  21.     x.val=text;
  22.     if(text.compareTo("f") !=0) {
  23.         x.st=new lista();
  24.         x.dr=new lista();
  25.         citire(x.st);
  26.         citire(x.dr);
  27.     }
  28.    
  29.     }
  30.    
  31.     static void afisare_preorder(lista x){
  32.         System.out.println(x.val);
  33.         if(x.st!=null) afisare_preorder(x.st);
  34.         else {
  35.             System.out.println(x.val);
  36.             x=x.dr;
  37.         }
  38.     }
  39.    
  40.    
  41.     public static void main(String[] args) throws IOException {
  42.         lista nod=new lista("abc");
  43.         citire(nod);
  44.         afisare_preorder(nod);
  45.        
  46.  
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement