null

MySql 行转列操作

亡梦爱人 提交于 2020-02-11 21:44:02
行转列操作 将行数据转为列数据展示 话不多说 开干 准备数据 CREATE TABLE ` t_score ` ( ` id ` int ( 11 ) NULL DEFAULT NULL , ` account ` varchar ( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , ` grade ` int ( 255 ) NULL DEFAULT NULL ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact ; INSERT INTO ` t_score ` VALUES ( 1 , 'match' , 85 ) ; INSERT INTO ` t_score ` VALUES ( 1 , 'chinese' , 80 ) ; INSERT INTO ` t_score ` VALUES ( 1 , 'english' , 99 ) ; INSERT INTO ` t_score ` VALUES ( 2 , 'match' , 90 ) ; INSERT INTO ` t_score ` VALUES ( 2 , 'chinese' , 80 ) ; INSERT

探究HashMap1.8的扩容

前提是你 提交于 2020-02-09 15:02:33
扩容前 扩容后 机制 else { // preserve order Node<K,V> loHead = null, loTail = null;//低指针 Node<K,V> hiHead = null, hiTail = null;//高指针 Node<K,V> next; do {//采用尾插法,与1.7头插法不同,不会产生环 next = e.next; //属于低链表 if ((e.hash & oldCap) == 0) { if (loTail == null) loHead = e; else loTail.next = e; loTail = e; } //属于高链表 else { if (hiTail == null) hiHead = e; else hiTail.next = e; hiTail = e; } } while ((e = next) != null); if (loTail != null) { loTail.next = null; newTab[j] = loHead;//newIndex = oldIndex } if (hiTail != null) { hiTail.next = null; newTab[j + oldCap] = hiHead;//newIndex = oldIndex + oldCap } } 来源:

二叉搜索树05--第六天

筅森魡賤 提交于 2020-02-09 15:02:21
1.何为二叉搜索树 1.1二叉搜索树的接口设计 1.2添加节点 1.3元素比较方案 1.4相关代码 1.BinarySearchTree类 package com.mj; import java.util.Comparator; import java.util.LinkedList; import java.util.Queue; import com.mj.printer.BinaryTreeInfo; @SuppressWarnings("unchecked") public class BinarySearchTree<E> implements BinaryTreeInfo { private int size; private Node<E> root; private Comparator<E> comparator; public BinarySearchTree() { this(null); } public BinarySearchTree(Comparator<E> comparator) { this.comparator = comparator; } public int size() { return size; } public boolean isEmpty() { return size == 0; } public void clear()

哈希表

Deadly 提交于 2020-02-09 12:52:56
哈希表(散列表)根据关键码值(Key)直接访问,加快查找的速度。 简单来说就是把数据分组,在进行查找的时候直接在对应的组里进行查找,以此减少查找数据时对不必要查找数据时所浪费的时间 package hashtab; import java.util.Scanner; public class HashTabDemo { public static void main(String[] args) { HashTab hashTab = new HashTab(7); String key = ""; Scanner scanner = new Scanner(System.in); while (true) { System.out.println("add"); System.out.println("list"); System.out.println("find"); System.out.println("del"); System.out.println("exit"); key = scanner.next(); switch (key) { case "a": int id = scanner.nextInt(); String name = scanner.next(); Emp emp = new Emp(id, name); hashTab.add(emp);

leetcode 160相交链表

人盡茶涼 提交于 2020-02-09 04:12:30
暴力解法当然可以遍历两个链表,不过time O(mn) space O(1)暂且不说, 方法一:双指针, time O(m+n),space O(1) 可以对比判断环形链表的快慢指针法。 这种方法构思十分十分十分巧妙,假设有两个链表,链表A: 1 2 3 * # 和链表B: a b c d e * # ,可以得出相交的第一个节点为*。那么A长度为la=5,*前面有lapre=3个元素;B长度为lb=7,*前面有lbpre=5个元素;可以发现lbpre+la=lapre+lb。 因此,只要用两个指针,每次前进一个节点,当pA到达末尾让其指向headB,当pB到达末尾让其指向headA那么当遍历10次后,两个指针都刚好到达*处,因此得到结果。 同时,针对无解的情况,记录两个链表的长度m和n,并且记录遍历次数i如果i>m+n时还没有满足条件的节点,可以断定无解;或者记录到达NULL的次数,如果第三次到达NULL之前还没有解,那么则无解。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode

Guava LoadingCache不能缓存null值

无人久伴 提交于 2020-02-08 11:29:34
测试的时候发现项目中的LoadingCache没有刷新,但是明明调用了refresh方法了。后来发现LoadingCache是不支持缓存null值的,如果load回调方法返回null,则在get的时候会抛出异常。 通过几个例子开看这个问题: public void test_loadNull() { LoadingCache<String, String> stringCache = CacheBuilder.newBuilder() .maximumSize(10) .build(new CacheLoader<String, String>() { @Override public String load(String s) throws Exception { System.out.println("xx"); if (s.equals("hello")) return "world"; else return null; } }); try { System.out.println(stringCache.get("hello")); // get触发load,load返回null则抛出异常: // com.google.common.cache.CacheLoader$InvalidCacheLoadException: CacheLoader returned null

MySQL----多表操作

烂漫一生 提交于 2020-02-08 02:33:49
##多表之间的关系 1、一对一(了解)    * 如:人和身份证   * 分析:一个人只有一个身份证,一个身份证只能对应一个人。 2、一对多(多对一)    * 如:部门和员工   * 分析:一个部门有多个员工,一个员工只能对应一个部门。 3、多对多    * 如:学生和课程   * 分析:一个学生可以选择很多们课程,一门课程也可以被很多学生选择。 实现关系 1、一对多(多对一)    * 如:部门和员工   * 实现方式:在多的一方建立外键,指向一的一方的主键。 2、多对多    * 如:部门和员工   * 实现方式:借助第三张中间表,至少包含两个字段,这两个字段作为第三张表的外键,分别指向两张主表的主键。 3、一对一    * 如:人和身份证   * 实现方式:可以在任意一方添加唯一外键指向另一方的主键。 案例: /*旅游线路案例 1、分类表和线路表是1 对 多的关系 2、线路表和用户表是多对多,需要创建中间表。 */ create table category( cid int primary key auto_increment, name varchar(64) not null unique ); create table routes( rid int primary key auto_increment, name varchar(128) not null

题21、合并两个有序链表

眉间皱痕 提交于 2020-02-06 04:25:08
一、题目 1 二、思路 三、代码 public class T0021 { public static void main ( String [ ] args ) { int [ ] nums1 = { 1 , 3 , 5 } ; int [ ] nums2 = { 2 , 4 , 6 } ; ListNode l1 = new ListNode ( nums1 [ 0 ] ) ; ListNode node = l1 ; for ( int i = 1 ; i < nums1 . length ; i ++ ) { node . next = new ListNode ( nums1 [ i ] ) ; node = node . next ; } ListNode l2 = new ListNode ( nums2 [ 0 ] ) ; node = l2 ; for ( int i = 1 ; i < nums2 . length ; i ++ ) { node . next = new ListNode ( nums2 [ i ] ) ; node = node . next ; } ListNode head = mergeTwoLists ( l1 , l2 ) ; while ( head != null ) { System . out . println (

When does malloc() in C return NULL?

淺唱寂寞╮ 提交于 2020-02-05 00:22:27
问题 Malloc returns a null when heap memory is insufficient OR when heap is super fragmented. What I would like to know is that if there are OTHER circumstances when malloc() returns a NULL? PS:Under what circumstances can malloc return NULL? didn't seem to answer my question 回答1: When does malloc() in C return NULL ? malloc() returns a null pointer when it fails to allocate the needed space. This can be due to: Out-of-memory in the machine (not enough bytes) Out-of-memory for the process (OS may

Can't Read Registry Key

若如初见. 提交于 2020-02-04 04:16:32
问题 give the code below, lastuser string returns null, however, if I use regedit to look at this key it has data associated with it. Is LoggedOnSAMuser a restricted key? public static string lastlogon() { string lastuser; RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI",false); if (registryKey != null) { lastuser = (string) registryKey.GetValue