-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMobilePhoneSet.java
101 lines (100 loc) · 2.48 KB
/
MobilePhoneSet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
public class MobilePhoneSet extends Myset
{
Myset setofmobile;
MobilePhoneSet(){
setofmobile=new Myset();
}
public void insertmobile(Object o){
setofmobile.Insert(o);
}
public void deletemobile(Object o)throws Exception{
try{
setofmobile.Delete(o);
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
}
public boolean isAMember(Object o){
return setofmobile.IsMember(o);
}
public MobilePhoneSet unionmobile(MobilePhoneSet o){
MobilePhoneSet c=new MobilePhoneSet();
c.setofmobile=setofmobile.Union(o.setofmobile);
return c;
}
public MobilePhoneSet intersectionmobile(MobilePhoneSet o){
MobilePhoneSet c=new MobilePhoneSet();
c.setofmobile=setofmobile.Intersection(o.setofmobile);
return c;
}
public MobilePhone findMobile(int id)throws Exception
{
MobilePhone temp=new MobilePhone(0);
setofmobile.aset.ptr=setofmobile.aset.head;
int flag=0;
while(setofmobile.aset.ptr.next!=null)
{
setofmobile.aset.ptr=setofmobile.aset.ptr.next;
temp=(MobilePhone)setofmobile.aset.ptr.data;
if(temp.id == id)
{
flag=1;
break;
}
}
if(flag==1)
return (MobilePhone)setofmobile.aset.ptr.data;
else
throw new Exception("Error - No mobile phone with identifier "+id+" found in the network");
}
public boolean findMobileAlter(int id)
{
MobilePhone temp=new MobilePhone(0);
setofmobile.aset.ptr=setofmobile.aset.head;
int flag=0;
while(setofmobile.aset.ptr.next!=null)
{
setofmobile.aset.ptr=setofmobile.aset.ptr.next;
temp=(MobilePhone)setofmobile.aset.ptr.data;
if(temp.id == id)
{
flag=1;
break;
}
}
if(flag==1)
return true;
else
return false;
}
/*public void printAll(){
setofmobile.aset.ptr=setofmobile.aset.head;
while(setofmobile.aset.ptr.next!=null)
{
setofmobile.aset.ptr=setofmobile.aset.ptr.next;
MobilePhone temp=(MobilePhone)setofmobile.aset.ptr.data;
if(temp.status()==true)
{
System.out.println(temp.id);
}
else
continue;
}
}*/
/*public static void main(String args[]){
MobilePhone k1=new MobilePhone(1234);
MobilePhone k2=new MobilePhone(2345);
MobilePhone k3=new MobilePhone(3456);
MobilePhone k4=new MobilePhone(4567);
MobilePhone k5=new MobilePhone(5678);
MobilePhoneSet w=new MobilePhoneSet();
w.insertmobile(k1.id);
w.insertmobile(k2.id);
w.insertmobile(k3.id);
w.insertmobile(k4.id);
w.insertmobile(k5.id);
w.printAll();
}*/
}