Professional Documents
Culture Documents
Fa CSC508
Fa CSC508
QUESTION 1
a)
Coordinator obj = (Coordinator)coordinatorLL.getFirst();
obj = coordinatorLL.getNext();
b)
LinkedList <Coordinator> civilEngineeringLL = new LinkedList<Coordinator> ();
civilEngineeringLL.insertAtBack(obj2);
coordinatorLL.removeFromFront();
temp.insertAtBack(obj2);
obj2 = coordinatorLL.getNext();
c)
Queue shortSleeveQ = new Queue();
double totPrice = 0;
while( !prodQueue.isEmpty() ) {
temp.enqueue(obj);
totPricel += obj.getPrice();
if ( obj.getType().equals(“shortSleeve”) ) {
shortSleeveQ.enqueue(obj);
else if ( obj.getType().equals(“shortSleeve”) ) {
shortPantsQ.enqueue(obj);
while ( !temp.isEmpty() ) {
prodQueue.enqueue(temp.dequeue() );
double totPriceSleeve = 0;
double totPricePant = 0;
while ( !shortSleeveQ.isEmpty() ){
temp.enqueue(obj2);
totPriceSleeve + = obj2.getPrice();
while ( !temp.isEmpty() ){
shortSleeveQ.enqueue(temp.dequeue() );
while ( ! shortPantsQ.isEmpty() ){
temp.enqueue(obj3);
totPricePlant + = obj3.getPrice();
while ( !temp.isEmpty() ){
shortPantsQ.enqueue(temp.dequeue() );
a)
4
5 6 6 10
2 40 40 8 3 3 3 3 13
Stack 22 22 11 11 11 11 88 88 88 88 88 88 75
Postfix 22 2 / 40 5 / * 3 6 4 + + -
Answer : 75
b)
Stack = 1
4
7
1
c)
foo (14,7) + 14
foo (7,6) + 7
foo (1,5) + 1
5
5+ 1 = 6
6 + 7 = 13
13 + 14 = 27
QUESTION 3
a)
void postOrder(Node t)
{
if (t != null )
{
postOrder(node.left );
postOrder(node.right );
System.out.print(node.key + “ “);
}
else
return;
}
class Node {
int key;
Node left, right;
C)
FY76
FY76
DD87
FY76
DD87
EU88
EU88
FY76
DD87
EU88
DD87 FY76
RD77
EU88
DD87 FY76
RD77
QA32
EU88
DD87 QA32
FY76 RD77
EU88
DD87 QA32
BL56 FY76
RD77
EU88
DD87 QA32
BL56
FY76 RD77
AA12
EU88
BL56 QA32
b)
38 27 43 3 9 82 10
38 27 43 3 9 82 10
38 27 43 3 9 82 10
38 27 43 3
82 10
38 27 43 3 82 10
43 38 27 3 82 10 9
82 43 38 27 10 9 3
c)
0 140
1 169
2
3 75 143
4
5 285
6 48 190
7
8
9 177
10 66 122
11
12
13
QUESTION 5
a)
From (1)
1 2 3 4 5 6 7
SW 0 2 - 1 - - -
FW T F F F F F F
1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T F F T F F F
1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T F T F F F
1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T T T F F F
1 2 3 4 5 6 7
SW 0 2 3 1 3 9 5
FW T T T T T F F
1 2 3 4 5 6 7
SW 0 2 3 1 3 6 5
FW T T T T T F T
1 2 3 4 5 6 7
SW 0 2 3 1 3 6 5
FW T T T T T T T
b)
visited = {}
visited = {(c,b)}
visited = {(c,b) , (c,d) }
visited = {(c,b),(c,d),(d,e)}
visited = {(c,b),(c,d),(d,e),(b,f)}
visited = {(c,b),(c,d),(d,e),(b,f),(e,a)}