Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Question Number 2, part A
- public void split()
- {
- Node <Asset> x = this.assets;
- Scanner in = new Scanner(System.in);
- while(x!=null)
- {
- if (x.getValue().getRooms()%2==0)
- {
- System.out.println("If you want to split an asset Please type 1, else please type 0");
- int t = in.nextInt();
- if(t==1)
- {
- Asset temp = x.getValue();
- Asset a = new Asset(temp.getAssetCode()+"A",temp.getStreet(),temp.getRooms()/2,temp.getPrice()*0.7);
- Asset a = new Asset(temp.getAssetCode()+"B",temp.getStreet(),temp.getRooms()/2,temp.getPrice()*0.7);
- Node <Asset> a1 = new Node <Asset> (a, new Node <Asset> (b, this.assets()));
- this.assets = remove(this.assets, x);
- this.assets = a1;
- }
- }
- x = x.getNext();
- }
- }
- //Remove a Node from A List function
- public static Node <Asset> remove(Node <Asset> ls, Node <Asset> pos)
- {
- if (pos==ls)
- return pos.getNext();
- Node <Asset> prev = L;
- while (prev.getNext() != pos)
- prev = prev.getNext();
- prev.setNext(pos.getNext());
- return lst
- }
- //Question Number 2, part B
- public static void cheap(RealEstateOffice [] of, int rooms)
- {
- String tempName = "No Office";
- int minPrice = Integer.MAX_VALUE;//Largest number an int can have
- for (int i = 0;i<of.length ;i++ )
- {
- Node <Asset> x = of[i].getAssets();
- while(x!=null)
- {
- if(x.getValue().getRooms() == rooms)
- {
- minPrice = x.getValue().getPrice();
- tempName = of[i].getOfficeName();
- }
- x = x.getNext();
- }
- }
- System.out.println(tempName);
- }
- //Question Number 3, Part A
- public static int count(BinNode<InfoTree> t, char x)
- {
- if (tr!=null)
- {
- int a = 0;
- if (tr.getValue().getTav() == x)
- a = 1;
- return a + count(t.getLeft()) + count(t.getRight());
- }
- return 0;
- }
- public static boolean sigma(BinNode<InfoTree> bt)
- {
- if (bt==null)
- return true;
- if(bt.getValue().getNum()== count(bt,bt.getValue().getChar()))
- return true && sigma(bt.getLeft()) && sigma(bt.getRight());
- return false;
- }
- //Question Number 3, Part B
- public static int sum(BinNode<InfoTree> t)
- {
- if (t == null)
- return 0;
- int x = 0;
- if(t.hasLeft())
- if(t.getLeft().getValue()>t.getValue())
- x += t.getLeft().getValue()
- if(t.hasRight())
- if(t.getRight().getValue()>t.getValue())
- x += t.getright().getValue()
- return x + sum(t.getLeft()) + sum(t.getRight());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement