-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b9cd94
commit 32a7d6a
Showing
20 changed files
with
386 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.