Question

CS 320: Test #2 Total 100 points 1177/2019 Name: Andjela Mihajlovic 1) You are given a Queue O n , and two pointer Q.tail and
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer(a)

Enqueue (Q, x)

{

//Queue Overflow Condition

if( Q.tail==Q.head)

{

PRINT(Queue Overflow)

exit(1)

}

Q[Q.tail]=x

if Q.tail==Q.length

Q.tail=1

else

Q.tail=Q.tail+1

}

Answer(b)

int Dequeue (Q)

{

//Queue Underflow Condition

if( Q.head== -1)

//because initially when no element is there in the queue, Q.head and Q.tail is set to -1

{

PRINT(Queue Underflow)

exit(1)

}

int a=Q[Q.head]

//condition for last element deletion

if(Q.head=Q.tail)

{

Q.head=-1

Q.tail= -1

}

else

{

Q.head=Q.head-1

}

}

Add a comment
Know the answer?
Add Answer to:
CS 320: Test #2 Total 100 points 1177/2019 Name: Andjela Mihajlovic 1) You are given a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE...

    HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...

  • CS-320 Computer Organization and Architecture Homework #7 Due: 04/15/2019 1. (25 points total) Consider the following...

    CS-320 Computer Organization and Architecture Homework #7 Due: 04/15/2019 1. (25 points total) Consider the following loop. LOOP: ld x10, e(x13) ld x11, 8 (x13) add x12, x10, x11 subi x13, x13, 16 bnez x12, LOOP Assume that perfect branch prediction is used (no stalls due to control hazards), that there are no delay slots, that the pipeline has full forwarding support, and that branches are resolved in the EX (as opposed to the ID) stage. (20 points) Show a...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • Please answer the questions below: 1. Given an example of the shortest IF statement in Modula-2....

    Please answer the questions below: 1. Given an example of the shortest IF statement in Modula-2. (“Shortest” means fewest number of lexemes.) 2. State whether or not each of the following language constructs is syntactically valid. For each invalid construct, give the number of the syntax rule that is violated. (a) Declaration: CONST mask = BITSET{9..11}; divisor = 512; (b) Declaration: PROCEDURE LessThan(addr1, addr2: ADDRESS): BOOLEAN; VAR r1, r2: POINTER TO REAL; BEGIN r1 := addr1; r2 := addr2; RETURN...

  • My Question is: I have to modify this program, even a small modification is fine. Can...

    My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...

  • My CSC 220 teacher has given this as a homework assignment and starting it has not...

    My CSC 220 teacher has given this as a homework assignment and starting it has not made much sense and am generally lost on this assignment help would be much appreciated. I put everything from the assignment power point slides she gave us in here so the expert has everything im working with as well. Dequeue Please implement your own Dequeue class which has following methods boolean add(E e)= void addLast(E e) void addFirst(E e) E getFirst( ) = E...

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

  • 1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class...

    1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...

  • In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is...

    In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is to complete the implementation of the classes specified as below. Y 1 Your Task You are given a class “Item” that contains one integer value, and two pointers. You are going to build a doubly linked list class DLinkedList. I describe the tasks below. Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure that the copy constructor makes...

  • Question 2. (24 points. Recall that in Assignment 1, we developed recursive algorithms for implementing the...

    Question 2. (24 points. Recall that in Assignment 1, we developed recursive algorithms for implementing the specification Given a non-decreasing array Aſ1..n], and given a value v, return a number r such that • ifr=0 then v does not occur in A[1..n] • ifr #0 then 1 <r<n and A[r] = v. In this question, we shall implement this specification by an iterative algorithm, build around a while loop of the form (with AA, BB, CC and CC2 to be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT