From 5ccfc7f58f4f9efd810c12a8f758bb2adaf85857 Mon Sep 17 00:00:00 2001 From: weewwccw <5572917+shifm@user.noreply.gitee.com> Date: Tue, 4 Feb 2020 12:52:31 +0800 Subject: [PATCH 1/2] week06 --- week_06/11/MyCircularDeque.md | 56 ++++++++++++++++++++++++ week_06/11/MyCircularQueue.md | 66 ++++++++++++++++++++++++++++ week_06/11/MyHashMap.md | 70 ++++++++++++++++++++++++++++++ week_06/11/MyHashSet.md | 43 ++++++++++++++++++ week_06/11/MyLinkedList.md | 82 +++++++++++++++++++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 week_06/11/MyCircularDeque.md create mode 100644 week_06/11/MyCircularQueue.md create mode 100644 week_06/11/MyHashMap.md create mode 100644 week_06/11/MyHashSet.md create mode 100644 week_06/11/MyLinkedList.md diff --git a/week_06/11/MyCircularDeque.md b/week_06/11/MyCircularDeque.md new file mode 100644 index 0000000..c8ae3b9 --- /dev/null +++ b/week_06/11/MyCircularDeque.md @@ -0,0 +1,56 @@ +class MyCircularDeque { public: /** Initialize your data structure here. Set the size of the deque to be k. */ MyCircularDeque(int k) { size = k; head = k - 1; tail = 0, cnt = 0; data.resize(k); } + +/** Adds an item at the front of Deque. Return true if the operation is successful. */ +bool insertFront(int value) { + if (isFull()) return false; + data[head] = value; + head = (head - 1 + size) % size; + ++cnt; + return true; +} + +/** Adds an item at the rear of Deque. Return true if the operation is successful. */ +bool insertLast(int value) { + if (isFull()) return false; + data[tail] = value; + tail = (tail + 1) % size; + ++cnt; + return true; +} + +/** Deletes an item from the front of Deque. Return true if the operation is successful. */ +bool deleteFront() { + if (isEmpty()) return false; + head = (head + 1) % size; + --cnt; + return true; +} + +/** Deletes an item from the rear of Deque. Return true if the operation is successful. */ +bool deleteLast() { + if (isEmpty()) return false; + tail = (tail - 1 + size) % size; + --cnt; + return true; +} + +/** Get the front item from the deque. */ +int getFront() { + return isEmpty() ? -1 : data[(head + 1) % size]; +} + +/** Get the last item from the deque. */ +int getRear() { + return isEmpty() ? -1 : data[(tail - 1 + size) % size]; +} + +/** Checks whether the circular deque is empty or not. */ +bool isEmpty() { + return cnt == 0; +} + +/** Checks whether the circular deque is full or not. */ +bool isFull() { + return cnt == size; +} +private: vector data; int size, head, tail, cnt; }; \ No newline at end of file diff --git a/week_06/11/MyCircularQueue.md b/week_06/11/MyCircularQueue.md new file mode 100644 index 0000000..53abffb --- /dev/null +++ b/week_06/11/MyCircularQueue.md @@ -0,0 +1,66 @@ +class MyCircularQueue { private int[] array; private int front = 0; private int rear = 0; private int size = 0; + +public: /** Initialize your data structure here. Set the size of the queue to be k. */ MyCircularQueue(int k) { array = new int[k]; } + +/** Insert an element into the circular queue. Return true if the operation is successful. */ +bool enQueue(int value) { + if (array.length == size) { + return false; + } + array[rear] = value; + rear = (rear + 1) % array.length; + size++; + return true; +} + +/** Delete an element from the circular queue. Return true if the operation is successful. */ +bool deQueue() { + if (size == 0) { + return false; + } + front = (front + 1) % array.length; + size--; + return true; + +} + +/** Get the front item from the queue. */ +int Front() { + if (size == 0) { + return -1; + } + return array[front]; + +} + +/** Get the last item from the queue. */ +int Rear() { + if (size == 0) { + return -1; + } + int index = (rear - 1 + array.length) % array.length; + return array[index]; +} + +/** Checks whether the circular queue is empty or not. */ +bool isEmpty() { + return size == 0; +} + +/** Checks whether the circular queue is full or not. */ +bool isFull() { + return size == array.length; +} +}; + +/** + +Your MyCircularQueue object will be instantiated and called as such: +MyCircularQueue* obj = new MyCircularQueue(k); +bool param_1 = obj->enQueue(value); +bool param_2 = obj->deQueue(); +int param_3 = obj->Front(); +int param_4 = obj->Rear(); +bool param_5 = obj->isEmpty(); +bool param_6 = obj->isFull(); +/ \ No newline at end of file diff --git a/week_06/11/MyHashMap.md b/week_06/11/MyHashMap.md new file mode 100644 index 0000000..465fbd7 --- /dev/null +++ b/week_06/11/MyHashMap.md @@ -0,0 +1,70 @@ +class MyHashSet { + +public class MyEntry{ public T data;//当前数据 public MyEntry next; } + +private MyEntry []tables;//数组 +private final int INIT_LEN=50; +public: /** Initialize your data structure here. */ MyHashSet() { tables=new MyEntry[INIT_LEN]; size=0; } + +void add(int key) { + if(data==null){ + return false; + } + int hashcode=data.hashCode();//计算哈希值 + int index=indexFor(hashcode);//定位存储的位置 + MyEntry head=tables[index];//取出该位置的第一个元素(链表的头) + MyEntry pNode=head;//查找链表中是否存在 + while(pNode!=null){ + if(pNode.data.hashCode()==hashcode&&(pNode.data==data||pNode.data.equals(data))){ + return false;//已经存在重复的元素 + } + pNode=pNode.next; + } + //不存在重复的元素或该位置为空,将该节点添加到链表的头 + MyEntry newNode=new MyEntry(); + newNode.data=data; + newNode.next=head; + tables[index]=newNode; + size++; +} + +void remove(int key) { + if(data==null){ + return false; + } + int hashcode=data.hashCode(); + int index=indexFor(hashcode); + MyEntry head=tables[index]; + MyEntry pNode=head; + if(pNode.data.hashCode()==hashcode&&(pNode.data==data||pNode.data.equals(data))){ + tables[index]=pNode.next; + size--; + return true; + } + while(pNode.next!=null){ + if(pNode.next.data.hashCode()==hashcode&&(pNode.next.data==data||pNode.next.data.equals(data))){ + pNode.next=pNode.next.next;//删除该元素 + size--; + return true; + } + pNode=pNode.next; + } + return false; +} + +/** Returns true if this set contains the specified element */ +bool contains(int key) { + boolean contains = false; + + Iterator iterator = this.iterator(); + for (E e = iterator.next(); iterator.hasNext() && !contains;) { + if (e == null) { + contains = o == null; + }else { + contains = e.equals(o); + } + } + + return contains; +} +}; \ No newline at end of file diff --git a/week_06/11/MyHashSet.md b/week_06/11/MyHashSet.md new file mode 100644 index 0000000..c4b303d --- /dev/null +++ b/week_06/11/MyHashSet.md @@ -0,0 +1,43 @@ +public class MyHashMap { private Entry[] table; private static Integer CAPACITRY = 8; private int size = 0; + +public MyHashMap() { this.table = new Entry[CAPACITRY]; } + +public int size() { + return size; +} +public: /** Initialize your data structure here. */ MyHashMap() { + +} + +/** value will always be non-negative. */ + public Object get(Object key) { + int hash = key.hashCode(); + int i = hash % CAPACITRY; + for(Entry entry = table[i];entry != null; entry = entry.next){ + if (entry.k.equals(key)) { + return entry.v; + } + } + return null; +} + +/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */ + public V put(K key, V value) { + int hash = key.hashCode(); + int i = hash % CAPACITRY; + for(Entry entry = table[i];entry != null; entry = entry.next){ + if (entry.k.equals(key)) { + V oldValue = entry.v; + entry.v = value; + return oldValue; + } + } + + addEntry(key, value, i); + + return null; +} + +/** Removes the mapping of the specified value key if this map contains a mapping for the key */ +public V remove(Object key) { Entry e = removeEntryForKey(key); return (e == null ? null : e.value); } +} \ No newline at end of file diff --git a/week_06/11/MyLinkedList.md b/week_06/11/MyLinkedList.md new file mode 100644 index 0000000..81ea38f --- /dev/null +++ b/week_06/11/MyLinkedList.md @@ -0,0 +1,82 @@ +class Node { Object value;//鑺傜偣鍏冪礌鍊 Node pre;//涓婁竴涓妭鐐 Node next;//涓嬩竴涓妭鐐 + +public Node(Object value) { + this.value = value; +} +} class MyLinkedList { + +/** Initialize your data structure here. */ +public MyLinkedList() { +Node cur;//鐩墠鎸囧悜鐨勮妭鐐 Node head;//澶寸粨鐐 Node end;//灏捐妭鐐 int size = 0; head = new Node("head"); end = new Node("end"); //璁剧疆澶村熬鐩歌繛 head.next = end; end.pre = head; } + +/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */ +public node get(int index) { + if (index < 0 || index >= size) { + throw new Exception("鏁扮粍涓嬫爣瓒婄晫锛"); + } + Node node = head.next; + for (int i = 1; i <= index; i++) { + + node = node.next;//杩唬涓轰笅涓涓妭鐐 + } + return node; +} + +/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */ +public void addAtHead(int val) { + +} + +/** Append a node of value val to the last element of the linked list. */ +public void addAtTail(int val) { + if (cur == null) { + cur = new Node(value); + head.next = cur; + cur.pre = head; + + } else { + Node node = new Node(value); + cur.next = node; + node.pre = cur; + cur = node;//灏哻ur鍏冪礌璁剧疆涓哄綋鍓嶆彃鍏ョ殑鑺傜偣 + } + cur.next = end; + end.pre = cur; + size++; +} + +/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */ +public void addAtIndex(int index, int val) { + if (index == size) { + this.add(value); + } else { + Node tmp = this.get(index);//褰撳墠index浣嶇疆鎵瀵瑰簲鐨勮妭鐐 + Node node = new Node(value);//褰撳墠瑕佹彃鍏ョ殑鑺傜偣 + + tmp.pre.next = node; + node.pre = tmp.pre; + node.next = tmp; + tmp.pre = node; + } + size++; +} + +/** Delete the index-th node in the linked list, if the index is valid. */ +public void deleteAtIndex(int index) { + Node tmp = this.get(index);//褰撳墠index浣嶇疆鎵瀵瑰簲鐨勮妭鐐 + tmp.pre.next = tmp.next; + tmp.next.pre = tmp.pre; + size--; +} +} + +/** + +Your MyLinkedList object will be instantiated and called as such: +MyLinkedList obj = new MyLinkedList(); +int param_1 = obj.get(index); +obj.addAtHead(val); +obj.addAtTail(val); +obj.addAtIndex(index,val); +obj.deleteAtIndex(index); +/ \ No newline at end of file -- Gitee From 60b3f2d76e9dca2b56a5e9c18d4363901723450a Mon Sep 17 00:00:00 2001 From: weewwccw <5572917+shifm@user.noreply.gitee.com> Date: Tue, 4 Feb 2020 14:38:38 +0800 Subject: [PATCH 2/2] week06 --- week_06/11/MyBatis3.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 week_06/11/MyBatis3.md diff --git a/week_06/11/MyBatis3.md b/week_06/11/MyBatis3.md new file mode 100644 index 0000000..68cb0ce --- /dev/null +++ b/week_06/11/MyBatis3.md @@ -0,0 +1,10 @@ +浠栨槸鎸佷箙鍖栧眰妗嗘灦锛屼篃灏辨槸鏁版嵁搴撴鏋躲 + +MyBatis锛 + +sql璇彞鎴戜滑寮鍙戜汉鍛樼紪鍐欙紝sql涓嶅け鍘荤伒娲绘 +浠栫殑sql鏂囦欢鎴戜滑鏄啓鍦ㄩ厤缃枃浠朵腑 + +鐗圭偣鏄細 + +sql涓巎ava鍒嗙 sql鏄紑鍙戜汉鍛樻帶鍒 鍗婅嚜鍔紝杞婚噺绾ф鏋 \ No newline at end of file -- Gitee