yay contains
parent
e2bf8c726e
commit
dc70fd4fb3
61
Set.java
61
Set.java
|
@ -9,7 +9,7 @@ public class Set<T>
|
|||
*/
|
||||
public Set(){
|
||||
this.first = null;
|
||||
length = 0;
|
||||
this.length = 0;
|
||||
this.last= null;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class Set<T>
|
|||
return this.length;
|
||||
}
|
||||
|
||||
public T get (int n){
|
||||
private T get (int n){
|
||||
Node<T> current = this.first;
|
||||
for ( int i = 0; i < n ; i++ ){
|
||||
if (current == null)return null;
|
||||
|
@ -54,9 +54,11 @@ public class Set<T>
|
|||
this.first = added;
|
||||
this.last = added;
|
||||
}
|
||||
else{ this.last.next = added;
|
||||
else{
|
||||
this.last.next = added;
|
||||
this.last = added;
|
||||
}
|
||||
this.length++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +78,7 @@ public class Set<T>
|
|||
current = current.next;
|
||||
}
|
||||
current.next.next = current.next;
|
||||
this.length--;
|
||||
}
|
||||
|
||||
public Set<T> intersection(Set<T> s){
|
||||
|
@ -88,14 +91,56 @@ public class Set<T>
|
|||
return tmp;
|
||||
}
|
||||
|
||||
public Set<T> unionUnoptimized(Set<T> s){
|
||||
Set<T> tmp = new Set<T>();
|
||||
for (int i = 0; i < s.size(); i++){
|
||||
tmp.add(s.get(i));
|
||||
}
|
||||
for (int i = 0; i < this.length; i++){
|
||||
if (!tmp.contains(this.get(i))) tmp.add(this.get(i));
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*public String toString(){
|
||||
Node <T> current = this.first;
|
||||
String tmp = "";
|
||||
public Set<T> union(Set<T> s){
|
||||
Set<T> tmp = new Set<T>();
|
||||
Node<T> current = s.first;
|
||||
while (current != null){
|
||||
tmp = tmp + (String)current.wert;
|
||||
tmp.add(current.wert);
|
||||
current = current.next;
|
||||
}
|
||||
current = this.first;
|
||||
while (current != null){
|
||||
if (!tmp.contains(current.wert)) tmp.add(current.wert);
|
||||
current = current.next;
|
||||
}
|
||||
return tmp;
|
||||
}*/
|
||||
}
|
||||
|
||||
public Set<T> difference(Set<T> s){
|
||||
Set<T> tmp = new Set<T>();
|
||||
Node <T> current = this.first;
|
||||
while (current!=null){
|
||||
if(!s.contains(current.wert))tmp.add(current.wert);
|
||||
current = current.next;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public boolean subset(Set<T> s){
|
||||
Node <T> current = this.first;
|
||||
while (current != null){
|
||||
if (!s.contains(current.wert)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public String toString(){
|
||||
Node <T> current = this.first;
|
||||
String tmp = "";
|
||||
while (current != null){
|
||||
tmp = tmp + current.wert + ", ";
|
||||
current = current.next;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
public class __SHELL4 extends bluej.runtime.Shell {
|
||||
public static void run() throws Throwable {
|
||||
|
||||
test.testset();
|
||||
|
||||
}}
|
|
@ -1,20 +1,47 @@
|
|||
#BlueJ package file
|
||||
editor.fx.0.height=0
|
||||
editor.fx.0.width=0
|
||||
editor.fx.0.x=0
|
||||
editor.fx.0.y=0
|
||||
dependency1.from=LinkedList
|
||||
dependency1.to=Node
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=List
|
||||
dependency2.to=Node
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Queue
|
||||
dependency3.to=Node
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Stack
|
||||
dependency4.to=Node
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=test
|
||||
dependency5.to=LinkedList
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=test
|
||||
dependency6.to=Node
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=test
|
||||
dependency7.to=List
|
||||
dependency7.type=UsesDependency
|
||||
dependency8.from=test
|
||||
dependency8.to=Set
|
||||
dependency8.type=UsesDependency
|
||||
dependency9.from=Set
|
||||
dependency9.to=Node
|
||||
dependency9.type=UsesDependency
|
||||
editor.fx.0.height=919
|
||||
editor.fx.0.width=2238
|
||||
editor.fx.0.x=80
|
||||
editor.fx.0.y=145
|
||||
objectbench.height=100
|
||||
objectbench.width=776
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8003731343283582
|
||||
package.editor.height=422
|
||||
package.editor.width=661
|
||||
package.editor.x=504
|
||||
package.editor.y=60
|
||||
package.editor.x=431
|
||||
package.editor.y=271
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.numDependencies=9
|
||||
package.numTargets=7
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
|
@ -24,9 +51,51 @@ readme.width=48
|
|||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=Node
|
||||
target1.name=Set
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=70
|
||||
target1.y=10
|
||||
target1.x=10
|
||||
target1.y=250
|
||||
target2.height=70
|
||||
target2.name=test
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=380
|
||||
target2.y=110
|
||||
target3.height=70
|
||||
target3.name=Node
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=70
|
||||
target3.y=10
|
||||
target4.height=70
|
||||
target4.name=List
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=140
|
||||
target4.y=90
|
||||
target5.height=70
|
||||
target5.name=Queue
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=120
|
||||
target5.x=10
|
||||
target5.y=170
|
||||
target6.height=70
|
||||
target6.name=LinkedList
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.width=120
|
||||
target6.x=10
|
||||
target6.y=90
|
||||
target7.height=70
|
||||
target7.name=Stack
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.width=120
|
||||
target7.x=140
|
||||
target7.y=170
|
||||
|
|
Loading…
Reference in New Issue