diff --git a/.idea/modules.xml b/.idea/modules.xml index 88e9223..cc4f015 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/lecture/.idea/$PROJECT_FILE$ b/lecture/.idea/$PROJECT_FILE$ new file mode 100644 index 0000000..58b7e3e --- /dev/null +++ b/lecture/.idea/$PROJECT_FILE$ @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/lecture/.idea/.gitignore b/lecture/.idea/.gitignore new file mode 100644 index 0000000..52769a9 --- /dev/null +++ b/lecture/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../../../:\Users\lizi2\Desktop\python_reptile_practice\UC_Berkeley_CS61B\lecture\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/lecture/.idea/checkstyle-idea.xml b/lecture/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..121d4a2 --- /dev/null +++ b/lecture/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/lecture/.idea/misc.xml b/lecture/.idea/misc.xml new file mode 100644 index 0000000..881809e --- /dev/null +++ b/lecture/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/lecture/.idea/modules.xml b/lecture/.idea/modules.xml new file mode 100644 index 0000000..f008c2e --- /dev/null +++ b/lecture/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lecture/.idea/qaplug_profiles.xml b/lecture/.idea/qaplug_profiles.xml new file mode 100644 index 0000000..3dfd21f --- /dev/null +++ b/lecture/.idea/qaplug_profiles.xml @@ -0,0 +1,465 @@ + + + + + \ No newline at end of file diff --git a/lecture/.idea/vcs.xml b/lecture/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/lecture/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lecture/out/production/lecture/IntList.class b/lecture/out/production/lecture/IntList.class new file mode 100644 index 0000000..fcc71ef Binary files /dev/null and b/lecture/out/production/lecture/IntList.class differ diff --git a/lecture/out/production/lecture/SList$IntNode.class b/lecture/out/production/lecture/SList$IntNode.class new file mode 100644 index 0000000..95e4ae2 Binary files /dev/null and b/lecture/out/production/lecture/SList$IntNode.class differ diff --git a/lecture/out/production/lecture/SList.class b/lecture/out/production/lecture/SList.class new file mode 100644 index 0000000..19b8051 Binary files /dev/null and b/lecture/out/production/lecture/SList.class differ diff --git a/lecture/out/production/lecture/lecture2_1.class b/lecture/out/production/lecture/lecture2_1.class new file mode 100644 index 0000000..8cb8b1c Binary files /dev/null and b/lecture/out/production/lecture/lecture2_1.class differ diff --git a/lecture/out/production/lecture/lecture2_2.class b/lecture/out/production/lecture/lecture2_2.class new file mode 100644 index 0000000..dc2977a Binary files /dev/null and b/lecture/out/production/lecture/lecture2_2.class differ diff --git a/lecture/out/production/lecture/lecture2_4.class b/lecture/out/production/lecture/lecture2_4.class new file mode 100644 index 0000000..d3dc4dc Binary files /dev/null and b/lecture/out/production/lecture/lecture2_4.class differ diff --git "a/lecture_2_\346\234\252\345\256\214\346\210\220\347\232\204\344\273\273\345\212\241.md" "b/lecture_2_\346\234\252\345\256\214\346\210\220\347\232\204\344\273\273\345\212\241.md" new file mode 100644 index 0000000..dfdf83a --- /dev/null +++ "b/lecture_2_\346\234\252\345\256\214\346\210\220\347\232\204\344\273\273\345\212\241.md" @@ -0,0 +1,5 @@ +# 双向链表(Intnode中的prev指针)(project1 待完成) + +# DList中会使用泛型,还没搞明白 + +# Lecture2_1 guide中如何不使用new操作符,就使得L的每个元素都加1,还不改变原来L的值? \ No newline at end of file diff --git a/lecture_guide/lecture_guide.iml b/lecture_guide/lecture_guide.iml new file mode 100644 index 0000000..28ac7fd --- /dev/null +++ b/lecture_guide/lecture_guide.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lecture_guide/src/IntNode.java b/lecture_guide/src/IntNode.java new file mode 100644 index 0000000..3a45642 --- /dev/null +++ b/lecture_guide/src/IntNode.java @@ -0,0 +1,50 @@ +/** + * @author Li Zezhong + * @create 2021-12-07 21:58 + */ +public class IntNode { + public int first; + public IntNode rest; + + public IntNode(int f, IntNode r) { + first = f; + rest = r; + } + + /** Return the size of the list using... recursion! */ + public int size() { + if(rest ==null){ + return 1; + } + return 1+rest.size(); + } + + /** Return the size of the list using no recursion! */ + public int iterativeSize() { + IntNode p = this; + int size = 1; + while(p.rest != null){ + size +=1; + p = p.rest; + } + return size; + } + + /** Returns the ith value in this list.*/ + public int get(int i) { + if(i==0){ + return first; + } + return rest.get(i-1); + } + + public static void main(String[] args) { + IntNode L = new IntNode(15, null); + L = new IntNode(10, L); + L = new IntNode(5, L); + +// System.out.println(L.iterativeSize()); +// System.out.println(L.get(0)); + System.out.println(L.iterativeSize()); + } +} diff --git a/lecture_guide/src/Lists1Exercises.java b/lecture_guide/src/Lists1Exercises.java new file mode 100644 index 0000000..a62cf04 --- /dev/null +++ b/lecture_guide/src/Lists1Exercises.java @@ -0,0 +1,65 @@ +/** + * @author Li Zezhong + * @create 2021-12-07 20:15 + */ +public class Lists1Exercises { + /** Returns an IntList identical to L, but with + * each element incremented by x. L is not allowed + * to change. */ + public static IntNode incrList(IntNode L, int x) { + /* Your code here. */ + int i=L.size()-1; + IntNode p=new IntNode(L.get(i)+x,null); + while(i>0){ + i -=1; + p = new IntNode(L.get(i)+x,p); + } + return p; + } + + + /** Returns an IntList identical to L, but with + * each element incremented by x. Not allowed to use + * the 'new' keyword. */ + public static IntNode dincrList(IntNode L, int x) { + IntNode p = L; + while(p !=null){ + p.first -=x; + p = p.rest; + } + return L; + } + + public static void main(String[] args) { + IntNode L = new IntNode(5, null); + L.rest = new IntNode(7, null); + L.rest.rest = new IntNode(9, null); + +// System.out.println(L.size()); +// System.out.println(L.iterativeSize()); + + // Test your answers by uncommenting. Or copy and paste the + // code for incrList and dincrList into IntList.java and + // run it in the visualizer. +// System.out.println(L.get(1)); + IntNode p = Lists1Exercises.incrList(L,2); + int i=0; +// System.out.println(p.size()); + while(i