-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionQueue.java
52 lines (39 loc) · 1.06 KB
/
TransactionQueue.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
package DSCoinPackage;
public class TransactionQueue {
public Transaction firstTransaction;
public Transaction lastTransaction;
public int numTransactions;
public TransactionQueue(){
numTransactions = 0;
firstTransaction = lastTransaction = null;
}
public void AddTransactions (Transaction transaction) {
if(numTransactions==0){
firstTransaction = lastTransaction = transaction;
}
else{
lastTransaction.next = transaction;
transaction.previous = lastTransaction;
lastTransaction = transaction;
}
numTransactions++;
}
public Transaction RemoveTransaction () throws EmptyQueueException {
if(numTransactions==0){
throw new EmptyQueueException();
}
else{
Transaction temp = firstTransaction;
firstTransaction = firstTransaction.next;
numTransactions--;
if(numTransactions==0)
lastTransaction = null;
else
firstTransaction.previous = null;
return temp;
}
}
public int size() {
return numTransactions;
}
}