diff --git a/week_06/11/MyBatis3.md b/week_06/11/MyBatis3.md new file mode 100644 index 0000000000000000000000000000000000000000..68cb0ce73713362bd554aa395f80ff941da158fc --- /dev/null +++ b/week_06/11/MyBatis3.md @@ -0,0 +1,10 @@ +他是持久化层框架,也就是数据库框架。 + +MyBatis: + +sql语句我们开发人员编写,sql不失去灵活性 +他的sql文件我们是写在配置文件中 + +特点是: + +sql与java分离 sql是开发人员控制 半自动,轻量级框架 \ No newline at end of file diff --git a/week_06/11/MyCircularDeque.md b/week_06/11/MyCircularDeque.md new file mode 100644 index 0000000000000000000000000000000000000000..c8ae3b9bdd746f425dde05dfff248c2383bdcea5 --- /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 0000000000000000000000000000000000000000..53abffbf45de8d4458bbe43bdf3086e277f10bbf --- /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 0000000000000000000000000000000000000000..465fbd7deefabfe9f1fabd3abd289c6dc6b0e069 --- /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 0000000000000000000000000000000000000000..c4b303d30c6908979245807786d7d8c74df8c05f --- /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 0000000000000000000000000000000000000000..81ea38f7c3b8a79c927f69677c15388b90e99a61 --- /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;//将cur元素设置为当前插入的节点 + } + 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