java-day16

1,集合框架

           Collection                   Map

       List            Set            TreeMap

      ArrayList       TreeSet         HashTable

      LinkedList      HashSet         HashMap

      Stack

      Queue

2,Set

迭代  

遍历(先序  中序   后序)

first()   add() ....

我爱你中国

与List比较

1,list有序              set无序

2,list可重复            set不可重复

3,list可以有null值      set不允许

 

 

3,树,根  树叶  兄弟   祖父   孙子   路径   长   深度   高   祖先   后裔   真祖先  真后裔

二叉树:每个节点最多有两个孩子节点(左孩子  右孩子)

二叉查找树:左<根<右

AVL树(平衡树):单旋   双旋

红黑树

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.*;

import java.util.List;

 

public class Test {

    public static void main(String[] args){

        /*TreeSet t = new TreeSet();

        t.add(8);

        t.add(2);

        t.add(3);

        t.add(9);

        t.add(1);

        t.add(4);

        t.add(5);

        Iterator ite = t.iterator();

        while (ite.hasNext()){

            System.out.print(ite.next()+"  ");

        }*/

       /* HashSet  t = new HashSet();

        t.add("我");

        t.add("爱");

        t.add("你");

        t.add("中");

        t.add("国");

        //HashSet t1 = t.clone();

        System.out.println(t.contains("我"));

 

        Iterator ite = t.iterator();

        while (ite.hasNext()){

            System.out.print(ite.next()+"  ");

        }*/

        /*TreeSet t = new TreeSet();

        ArrayList a = new ArrayList();

        t.add(null);

        //a.add(null);

        System.out.println(t.size());

        System.out.println(a.size());*/

        /*ArrayList a = new ArrayList();

        for(int i=1;i<=10;i++){

            a.add(i);

        }

        ArrayList b = new ArrayList();

        while(a.size()>0){

            int i = (int)(Math.random()*a.size());

            b.add(a.get(i));

            a.remove(i);

        }

        System.out.println(b);

        Collections.sort(b);

        System.out.println(b);

        Collections.sort(b,new MySort());

        System.out.println(b);*/

 

        /*Set set = new HashSet();

        set.add("xiao1");

        set.add("xiao2");

        set.add("xiao3");

        set.add("xiao3");

        set.add("xiao5");

 

        for (Object s:set) {

            System.out.print(s+" ");

        }

        System.out.println();

        Iterator it = set.iterator();

        while(it.hasNext()){

            System.out.print(it.next()+" ");

        }

*/

 

 

       /* JFrame jf = new JFrame("窗口");

        jf.setBounds(100,100,500,500);

        jf.setBackground(new Color(0,0,0));

        JPanel jp = new JPanel();

        JButton jb = new JButton("这是一个按钮");

        jb.addActionListener(new ActionListener() {

            @Override

            public void actionPerformed(ActionEvent e) {

 

            }

        });

        jp.add(jb);

        jf.add(jp);

        jf.setVisible(true);*/

       /*

import java.util.Comparator;

 

public class MySort implements Comparator {

    @Override

    public int compare(Object o1, Object o2) {

        /*Integer a = (Integer)o1;

        Integer b = (Integer)o2;

        if(a>b){

            return -1;

        }

        return 1;*/

        PuKe p1 = (PuKe)o1;

        PuKe p2 = (PuKe)o2;

        if(p1.getColor()==p2.getColor()){

             if(p1.getValue()>p2.getValue()){

                 return -1;

             }

             return 1;

        }else if((int)(p1.getColor().charAt(0))>(int)(p2.getColor().charAt(0))){

            return -1;

        }else {

            return 1;

        }

 

    }

}

 

 

PUKE

 

import java.util.Objects;

 

public class PuKe {

    private String color;

    private int value;

 

    public PuKe() {

    }

 

    public PuKe(String color, int value) {

        this.color = color;

        this.value = value;

    }

 

    public String getColor() {

        return color;

    }

 

    public void setColor(String color) {

        this.color = color;

    }

 

    public int getValue() {

        return value;

    }

 

    public void setValue(int value) {

        this.value = value;

    }

 

    @Override

    public String toString() {

        return "PuKe{" +

                "color='" + color + '\'' +

                ", value=" + value +

                '}';

    }

}

Set set = xiPai();

测试

 

 

 System.out.println(set);

        ArrayList a = new ArrayList(set);

        paiXu(a);

        System.out.println(a);*/

 

        PuKe p1 = new PuKe("草花",3);

        PuKe p2 = new PuKe("红桃",2);

        comp(p1,p2);

    }

    private static Set xiPai(){

        Set set = new HashSet();

        set.add(new PuKe("黑桃",2));

        set.add(new PuKe("黑桃",8));

        set.add(new PuKe("黑桃",6));

        set.add(new PuKe("红桃",5));

        set.add(new PuKe("草花",5));

        set.add(new PuKe("方块",1));

        return set;

    }

    private static List paiXu(List list){

 

        Collections.sort(list,new MySort());

        return list;

    }

    private static void comp(PuKe p1,PuKe p2){

 

        if(p1.getValue()>p2.getValue()){

            System.out.println("p1>p2");

        }else if(p1.getValue()<p2.getValue()){

            System.out.println("p1<p2");

        }else {

            int a=0,b=0;

            if(p1.getColor()=="黑桃"){

                a = 4;

            }

            if(p1.getColor()=="红桃"){

                a = 3;

            }

            if(p1.getColor()=="草花"){

                a = 2;

            }

            if(p1.getColor()=="方块"){

                a = 1;

            }

            if(p2.getColor()=="黑桃"){

                b = 4;

            }

            if(p2.getColor()=="红桃"){

                b = 3;

            }

            if(p2.getColor()=="草花"){

                b = 2;

            }

            if(p2.getColor()=="方块"){

                b = 1;

            }

            if(a>b){

                System.out.println("p1>p2");

            }else if(a<b){

                System.out.println("p1<p2");

            }else {

                System.out.println("p1==p2");

            }

        }                                                        

    }

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值