Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SIs210 3. Write the output of the following code Test 02 Review Question SM08 St

ID: 3912076 • Letter: S

Question

SIs210 3. Write the output of the following code Test 02 Review Question SM08 String s -"CSIS210" Queue stk new LinkedListO; for( char c:s.toCharArrayOM stk.enqueue(c); for(int i-o; ic4;++i) stk.getFront for(int i-o; ic3; ++i) System.out.print(stk.dequeue) for(int i-o; k4; ++i) System.out.print(stk.getFront0) 4. What is the output of the following code fragment String s "AUK University"; Queue stk- new LinkedList0; for(int i-s.tochararray).length-1;b-o- Stk.enqueue(s.tocharacterOi]) for(int i-o; i

Explanation / Answer

3) Queue will contain : C S I S 2 1 0

=> getFront() 4 times ---> C C C C
It will give us the front element without removing it

=> dequeue() 3 times ---> C S I
It will give us the queue element one by one and remove it

=> getFront() 4 times ---> S S S S
It will give us the front element without removing it


4) Queue will contain : y t i s r e v i n u K U A

=> getFront() 4 times ---> y y y y
It will give us the front element without removing it

=> dequeue() 2 times ---> y t
It will give us the queue element one by one and remove it

=> s.length() is 14 ---> i i i i i i...14 times

5) AUK2016

QQ qill contain 6 1 0 2 K U A

q will contain 6 1 0 2 K U A
It will Output 6 1 0 2 K U A



6) Linked List

void enqueue(int data)

{

QNode *newAdd = newNode(data);

    if (queue->rear == NULL)

    {

queue->front = queue->rear = newAdd;

       return;

    }

queue->rear->next = newAdd;

queue->rear = newAdd;

}



Array Representation

void enqueue(int item)

{

    if (isFull(queue))

        return;

    queue->rear = (queue->rear + 1)%queue->capacity;

    queue->array[queue->rear] = item;

    queue->size = queue->size + 1;

}