Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Речник---------------------------------------------------------------------------------------------------------------------------
- package SLLHashTables;
- import java.util.Scanner;
- public class recnik {
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- System.out.println("Vnesi kolku zborovi kje ima recnikot. . .");
- int n=Integer.parseInt(in.nextLine());
- SLLHT<String,String> tabela=new SLLHT<String,String>(n);
- for(int i=0;i<n;i++){
- String s;
- s=in.nextLine();
- String[] s1=s.split(" ");
- tabela.insert(s1[0].toLowerCase(), s1[1].toLowerCase());
- }
- System.out.println("Vnesi go tekstot. . .");
- String s2;
- s2=in.nextLine();
- String[] s3=s2.split(" ");
- for(int i=0;i<s3.length;i++){
- s3[i]=s3[i].toLowerCase();
- if(s3[i].charAt(s3[i].length()-1)=='.'||s3[i].charAt(s3[i].length()-1)=='!'||s3[i].charAt(s3[i].length()-1)=='?'||s3[i].charAt(s3[i].length()-1)==',')
- s3[i]=s3[i].substring(0, s3[i].length()-1);
- if(tabela.find(s3[i].toLowerCase())!=null){
- System.out.print(tabela.find(s3[i].toLowerCase()).info.value +" ");
- }
- if(tabela.find(s3[i].toLowerCase())==null){
- System.out.print("? ");
- }
- }
- }
- }
- Висина | Број на јазли | Дедо-внук ----------------------------------------------------------------------------------------------
- package binarysearchtrees;
- import java.lang.reflect.Array;
- public class rekurzijaVisina {
- static int rekurzija(BNode<Integer> root){
- int l;
- int d;
- if (root==null) return -1;
- else {
- d= rekurzija(root.right)+1;
- l= rekurzija(root.left)+1;
- }
- if(d>l)return d;
- else return l;
- }
- static int jazlirekurzija(BNode<Integer> root){
- if (root==null) return 0;
- else
- return 1+jazlirekurzija(root.right)+jazlirekurzija(root.left);
- }
- static BNode<Integer> binarno(int [] nizica,int poc, int kraj){
- int n=(poc+kraj)/2;
- if (poc==kraj){
- return new BNode<Integer>(nizica[n]);
- }
- else{
- BNode<Integer> pom=new BNode<Integer>(nizica[n]);
- pom.left=binarno(nizica,poc,n-1);
- pom.right=binarno(nizica,n+1,kraj);
- return pom;
- }
- }
- static void dedo(BNode<Integer> root){
- if(root.right==null&&root.left==null){
- return;
- }
- else {
- if(root.right!=null){
- if(root.right.right!=null)
- System.out.println(root.right.right.info+" e vnuk na "+root.info);
- if(root.right.left!=null)
- System.out.println(root.right.left.info+" e vnuk na "+root.info);
- }
- if(root.left!=null){
- if(root.left.left!=null)
- System.out.println(root.left.left.info+" e vnuk na "+root.info);
- if(root.left.right!=null)
- System.out.println(root.left.right.info+" e vnuk na "+root.info);
- }
- if(root.left!=null) dedo(root.left);
- if(root.right!=null) dedo(root.right);
- }
- }
- static int dedo1(BNode<Integer> root){
- int n1=0;
- int n2=0;
- int n3=0;
- int n4=0;
- if(root.right==null&&root.left==null){
- return 0;
- }
- else {
- if(root.right!=null){
- if(root.right.right!=null)
- n1=1;
- if(root.right.left!=null)
- n2=1;
- }
- if(root.left!=null){
- if(root.left.left!=null)
- n3=1;
- if(root.left.right!=null)
- n4=1;
- }
- if(root.right!=null&&root.left!=null)
- return n1+n2+n3+n4+dedo1(root.left)+dedo1(root.right);
- else if(root.right==null&&root.left!=null)
- return n1+n2+n3+n4+dedo1(root.left);
- else if(root.right!=null&&root.left==null)
- return n1+n2+n3+n4+dedo1(root.right);
- }
- return dedo1(root.right)+dedo1(root.left);
- }
- public static void main(String[] args) {
- int [] a= {1,2,4,6,7,10,15};
- BSTree <Integer> tree = new BSTree<Integer>();
- tree.root= binarno(a, 0, a.length-1);
- tree.inorder();
- BSTree <Integer> tree1 = new BSTree<Integer>();
- BNode<Integer> b1=new BNode<Integer>(2);
- BNode<Integer> b2=new BNode<Integer>(7);
- BNode<Integer> b3=new BNode<Integer>(5);
- BNode<Integer> b4=new BNode<Integer>(1);
- BNode<Integer> b5=new BNode<Integer>(6);
- BNode<Integer> b6=new BNode<Integer>(9);
- BNode<Integer> b7=new BNode<Integer>(5);
- BNode<Integer> b8=new BNode<Integer>(11);
- BNode<Integer> b9=new BNode<Integer>(4);
- b1.left=b2;
- b1.right=b3;
- b2.left=b4;
- b2.right=b5;
- b5.left=b7;
- b5.right=b8;
- b3.right=b6;
- b6.left=b9;
- tree1.root=b1;
- dedo(b1);
- System.out.println(dedo1(b1));
- BNode<Integer> root=new BNode<Integer>(1);
- BNode<Integer> a1=new BNode<Integer>(1);
- BNode<Integer> a2=new BNode<Integer>(1);
- BNode<Integer> a3=new BNode<Integer>(1);
- BNode<Integer> a4=new BNode<Integer>(1);
- root.left=a1;
- a1.left=a2;
- a1.right=a3;
- a3.left=a4;
- System.out.println(rekurzija(root));
- System.out.println(jazlirekurzija(root));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement