PhiladelphiaUniversity

Lecturer :Dr. Samer Hanna and

Mr. A. Obaidat

Internal Examiner: Dr. Ali Fouad

Coordinator: Dr. Samer Hanna

Object Oriented Data Structures

(0721221 ) Sections1 and 2 First Exam First Semester of 2017-2018

Date:26/11/ 2017------Time: 50 min.

Question 1:(6 marks)

A)

Stack: is a linear data structure where first element inserted in it is the last element deleted from it.

Queue: is a linear data structure where first element inserted in it is the first element deleted from it.

B)

Ordered list: is a linear data structure where all elements stored in it are sorted and after any delete or insert operation the element still sorted.

unordered list: is a linear data structure where its elements stored in it are not sorted and after any delete or insert operation the elements could be in any order.

C)

Hash table: use a function to determine the position of an item to store or delete or to search.

Graph: set of nodes connected by set of edges.

D)Memory allocation in array and Memory allocation in linked list.

Memory allocation in array is static; its size is fixed even if there are only few items stored in it at any time.

Memory allocation in linked list is dynamic; its size is changed according to the number of items stored in it at any time.

Question 2: (4 marks)

A)

B)

Question 3: (4 marks)

A)

List<Integer> marks = new List<Integer>();

Scanner s = new Scanner(System.in);

Int m;

for(int I = 0; I < 30; i++)

{

System.out.println(“Enter student mark:”);

m= s.nextInt();

marks.add(m);

}

int count = 0;

Integer item = marks.first();

while (item!= null)

{

If(item == 60)

count++;

item = marks.next();

}

System.out.println(count);

B)

Integer item2 = marks.first();

while (item2!= null)

{

If(item2 > 50)

mark2.add(item2);

item2 = marks.next();

}

int sum =0;

Integer item3 = mark2.first();

while (item3!= null)

{

Sum+=item3;

Item3 = mark2.next();

}

System.out.println(sum/mark2.size());

Question 4: (6 marks)

A)

Node<Integer> x = new Node<Integer >(30,null);

x.next=F.next;

F.next=x;

B)

L = L.next;

C)

Node<Integer> loc = L1;

int sum = 0;

While(loc != null)

{

sum+= loc.data;

loc=loc.next;

}

System.out.println(sum);

Question 5: (4 marks)

A)

Create class student that has two attribute: student name (string) and student mark (integer)

B)

Public intrank(String name)

{

Student s = studentlist.first()

Int mark = 1;

While(s!= null)

{

If(s.name == name)

{

mark = s.mark

break;

}

S = studentlist.next();

}

Student s2 = studentlist.first()

Int rank = 1;

While(s2!= null)

{

If(s2.mark > mark)

{

rank++;

}

S2 = studentlist.next();

}

return rank;

}