Skip to content

Commit

Permalink
增加Discussion部分
Browse files Browse the repository at this point in the history
  • Loading branch information
lzz19980125 committed Dec 12, 2021
1 parent 8b9cd94 commit 32a7d6a
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Lab/Lab.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
47 changes: 47 additions & 0 deletions Lab/src/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @author Li Zezhong
* @create 2021-12-12 18:16
*/

public class Foo {
public int x, y;
public Foo (int x, int y) {
this.x = x;
this.y = y;
}

public static void switcheroo (Foo a, Foo b) {
Foo temp = a;
a = b;
b = temp;
}

public static void fliperoo (Foo a, Foo b) {
Foo temp = new Foo(a.x, a.y);
a.x = b.x;
a.y = b.y;
b.x = temp.x;
b.y = temp.y;
}

public static void swaperoo (Foo a, Foo b) {
Foo temp = a;
a.x = b.x;
a.y = b.y;
b.x = temp.x;
b.y = temp.y;
}

public static void main (String[] args) {
Foo foobar = new Foo(10, 20);
Foo baz = new Foo(30, 40);
switcheroo(foobar, baz);
System.out.println("foobar.x="+foobar.x+" foobar.y="+foobar.y+" baz.x="+baz.x+" baz.y="+baz.y);
System.out.println();
fliperoo(foobar, baz);
System.out.println("foobar.x="+foobar.x+" foobar.y="+foobar.y+" baz.x="+baz.x+" baz.y="+baz.y);
System.out.println();
swaperoo(foobar, baz);
System.out.println("foobar.x="+foobar.x+" foobar.y="+foobar.y+" baz.x="+baz.x+" baz.y="+baz.y);
}
}
98 changes: 98 additions & 0 deletions Lab/src/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @author Li Zezhong
* @create 2021-12-10 20:33
*/


public class IntList{
int first;
IntList rest;
public IntList(int f, IntList r){
this.first = f;
this.rest = r;
}
public int size(){
if(this.rest == null){
return 1;
}
return 1+this.rest.size();
}
public int IterativeSize(){
IntList p;
int result=0;
p = this;
while(p !=null){
result +=1;
p = p.rest;
}
return result;
}
public int get(int n){
if(n==0){
return this.first;
}
return this.rest.get(n-1);
}
public int IterativeGet(int n){
IntList p=this;
while(n!=0){
p = p.rest;
n -=1;
}
return p.first;
}
public void addFirst(int x){
int y = first;
this.first = x;
this.rest = new IntList(y,null);
}
public static void print_List(IntList L){
IntList n = L;
while(n !=null){
System.out.println(n.first);
n = n.rest;
}
}
public static void dSquareList(IntList L){
IntList p=L;
while(p!=null){
p.first *= p.first;
p = p.rest;
}
}
public static IntList copy(IntList L){
IntList p = new IntList(L.first,null);
IntList n = p;
IntList m = L;
while(m.rest!=null){
m = m.rest;
p.rest = new IntList(m.first,null);
p = p.rest;
}
return n;
}
public static IntList squareListIterative(IntList L){
IntList p = copy(L);
dSquareList(p);
return p;
}
public static IntList dcatenate(IntList A, IntList B){
IntList p = A;
while(p.rest!=null){
p = p.rest;
}
p.rest = B;
return A;
}
public static IntList catenate(IntList A, IntList B){
IntList p = copy(A);
IntList m = p;
while(p.rest!=null){
p = p.rest;
}
p.rest = B;
return m;
}
}


33 changes: 33 additions & 0 deletions Lab/src/Lab2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @author Li Zezhong
* @create 2021-12-10 20:34
*/


public class Lab2 {
public static void main(String[] args) {
IntList list1 = new IntList(3,null);
list1.rest = new IntList(2,null);
list1.rest.rest = new IntList(1,null);

IntList list2 = new IntList(6,null);
list2.rest = new IntList(5,null);
list2.rest.rest = new IntList(4,null);

// IntList.print_List(list1);
// IntList.print_List(IntList.copy(list1));
// IntList.dSquareList(list1);
// IntList.print_List(list1);
// IntList.print_List(IntList.squareListIterative(list1));
// System.out.println();
// IntList.print_List(list1);
// IntList.print_List(IntList.dcatenate(list1,list2));
// IntList.print_List(IntList.catenate(list1,list2));
// System.out.println();
// IntList.print_List(list1);


}
}


90 changes: 56 additions & 34 deletions lecture/src/lecture2_2.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,59 @@
/** Single List */
public class lecture2_2 {
public static void main(String[] args) {
SList<Number> L = new SList<>(15);
SList<Integer> L = new SList<>(63,15);
L.addFirst(10);
L.addFirst(5);
int x = L.getFirst();
System.out.println(x);
System.out.println(L.size());
L.addLast(1);
System.out.println(L.size());
System.out.println(L.getLast());

L.positive_print();
System.out.println();
L.negative_print();
}
}


class SList<Number> {
static class IntNode{
public int item;
class SList<buber> {
class IntNode{
public buber item;
public IntNode next;
public IntNode prev;
// public IntNode prev;
public IntNode(int i,IntNode n){
public IntNode(buber i,IntNode n){
item = i;
next = n;
}
public IntNode(buber i,IntNode n,IntNode m){
item = i;
next = n;
prev = m;
}
}
private IntNode sentinel;
private int size;
private IntNode last;
public SList(){
sentinel = new IntNode(63,null);
last = sentinel.next;
public SList(buber intnode){
sentinel = new IntNode(intnode,null,null);
last = sentinel;
size = 0;
}
public SList(int x){
sentinel = new IntNode(63,null);
sentinel.next = new IntNode(x,null);
last = sentinel.next;
public SList(buber intnode,buber x){
sentinel = new IntNode(intnode,null,null);
sentinel.next = new IntNode(x,null,sentinel);
size = 1;
last = sentinel.next;
}
public void addFirst(int y){
sentinel.next = new IntNode(y,sentinel.next);
public void addFirst(buber y){
sentinel.next = new IntNode(y,sentinel.next,sentinel);
if(sentinel.next.next!=null){
sentinel.next.next.prev = sentinel.next;
} else{
last = sentinel.next;
}
size +=1;
}
public int getFirst(){
public buber getFirst(){
return sentinel.next.item;
}
public int getLast(){
public buber getLast(){
return last.item;
}
// public void addLast(int x){
Expand All @@ -64,23 +71,38 @@ public int getLast(){
// p.next = new IntNode(x,null);
// size +=1;
// }
public void addLast(int x){
last.next = new IntNode(x,null);
public void addLast(buber x){
last.next = new IntNode(x,null,last);
last = last.next;
size +=1;
}
public static int size(IntNode p){
if(p.next ==null){
return 1;
// public static int size(IntNode p){
// if(p.next ==null){
// return 1;
// }
// return 1+size(p.next);
// }
// public int size(){
// return size(sentinel.next);
// }
public int size(){
return size;
}
public void positive_print(){
IntNode p=sentinel.next;
while(p !=last){
System.out.println(p.item);
p = p.next;
}
return 1+size(p.next);
System.out.println(p.item);
}
public int size(){
return size(sentinel.next);
public void negative_print(){
IntNode p=last;
while(p !=sentinel){
System.out.println(p.item);
p = p.prev;
}
}
// public int size(){
// return size;
// }
}


Expand Down
Loading

0 comments on commit 32a7d6a

Please sign in to comment.