In java  by using this Queue class: public class Queue { private int rear, front; private Object[] elements; Queue(int capacity) { elements = new Object[capacity]; rear = -1; front = 0; } void enqueue(Object data) { if (isFull()) { System.out.println("Queue overflow"); } else { rear = (rear + 1) % elements.length; elements[rear] = data; } } Object dequeue() { if (isEmpty()) { System.out.println("Queue empty"); return null; } else { Object retData = elements[front]; elements[front] = null; front = (front + 1) % elements.length; return retData; } } Object peek() { if (isEmpty()) { System.out.println("Queue is empty"); return null; } else { return elements[front]; } } boolean isEmpty() { return elements[front] == null; } boolean isFull() { return (front == (rear + 1) % elements.length && elements[front] != null && elements[rear] != null); } int size() { if (rear >= front) { return rear - front + 1; } else if (elements[front] != null) { return elements.length - (front - rear) + 1; } else { return 0; } } void majorityElement() { int majorcount = 0; int n = size(); Object major = elements[front]; for (int i = front; i <= rear; i++) { int count = 0; Object p = elements[i]; for (int j = 0; j <= rear; j++) { Object c = elements[j]; if (p.equals(c)) { count++; } } if (count > majorcount) { majorcount = count; major = p; } } if (majorcount > (n / 2)) { System.out.println(" major element is " + major); } else { System.out.println(" no major element found"); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In java 

by using this Queue class:


public class Queue {
private int rear, front;
private Object[] elements;

Queue(int capacity) {
elements = new Object[capacity];
rear = -1;
front = 0;
}

void enqueue(Object data) {
if (isFull()) {
System.out.println("Queue overflow");
} else {
rear = (rear + 1) % elements.length;
elements[rear] = data;
}
}

Object dequeue() {
if (isEmpty()) {
System.out.println("Queue empty");
return null;
} else {
Object retData = elements[front];
elements[front] = null;
front = (front + 1) % elements.length;
return retData;
}
}

Object peek() {
if (isEmpty()) {
System.out.println("Queue is empty");
return null;
} else {
return elements[front];
}
}

boolean isEmpty() {
return elements[front] == null;
}

boolean isFull() {
return (front == (rear + 1) % elements.length &&
elements[front] != null && elements[rear] != null);
}

int size() {
if (rear >= front) {
return rear - front + 1;
} else if (elements[front] != null) {
return elements.length - (front - rear) + 1;
} else {
return 0;

}
}

void majorityElement() {
int majorcount = 0;

int n = size();
Object major = elements[front];
for (int i = front; i <= rear; i++) {
int count = 0;
Object p = elements[i];
for (int j = 0; j <= rear; j++) {
Object c = elements[j];
if (p.equals(c)) {
count++;
}
}
if (count > majorcount) {
majorcount = count;
major = p;
}

}
if (majorcount > (n / 2)) {
System.out.println(" major element is " + major);
} else {
System.out.println(" no major element found");
}

}
}

2- Write a Java main program that:
- creates a circular queue (g)
- randomly adds 10 DNA nucleotides into q
- randomly generate a number (x) and applies the mutation operation on the x'h nucleotide.
There are four different types of DNA nucleotides: adenine (A), thymine (T), guanine (G), and cytosine (C).
Mutation is the process of randomly changing one bit of information in a DNA sequence with its complement.
Adenine and Thymine are complementary to each other, and Guanine and Cytosine are complementary to each other.
Print the content of the queue before and after mutation operation.
At the end of the program, the queue must be full.
Еxample:
front
rear
а: А т т с с AGA АТ
randomly generated number: 3
front
rear
q: A T G c CA G A A T
Notes:
- You must use ONLY queue data structure. Don't use other different data structures like string, normal (pure) array, stack, array list, SLL, or DLL.
- Don't write any other method in the Queue class. All methods must be written in the main program.
Transcribed Image Text:2- Write a Java main program that: - creates a circular queue (g) - randomly adds 10 DNA nucleotides into q - randomly generate a number (x) and applies the mutation operation on the x'h nucleotide. There are four different types of DNA nucleotides: adenine (A), thymine (T), guanine (G), and cytosine (C). Mutation is the process of randomly changing one bit of information in a DNA sequence with its complement. Adenine and Thymine are complementary to each other, and Guanine and Cytosine are complementary to each other. Print the content of the queue before and after mutation operation. At the end of the program, the queue must be full. Еxample: front rear а: А т т с с AGA АТ randomly generated number: 3 front rear q: A T G c CA G A A T Notes: - You must use ONLY queue data structure. Don't use other different data structures like string, normal (pure) array, stack, array list, SLL, or DLL. - Don't write any other method in the Queue class. All methods must be written in the main program.
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education