SlideShare a Scribd company logo
1 of 7
Download to read offline
Program 1 :
public class QueueUsingArray {
private static final int queueCapacity = 20;
int arr[] = new int[queueCapacity];
int size = 0;
int top = -1;
int rear = 0;
public void pushinQueue(int pushedElement) {
if (top < queueCapacity - 1) {
top++;
arr[top] = pushedElement;
System.out.println("Element " + pushedElement
+ " is pushed to Queue !");
display();
} else {
System.out.println("Overflow !");
}
}
public void pop() {
if (top >= rear) {
rear++;
System.out.println("Pop operation done !");
display();
} else {
System.out.println("Underflow !");
}
}
public void display() {
if (top >= rear) {
System.out.println("Elements in Queue : ");
for (int i = rear; i <= top; i++) {
System.out.println(arr[i]);
}
}
}
public static void main(String[] args) {
QueueUsingArray obj = new QueueUsingArray();
obj.pop();
obj.pushinQueue(20);
obj.pushinQueue(18);
obj.pushinQueue(67);
obj.pushinQueue(343);
obj.pop();
obj.pushinQueue(203);
obj.pushinQueue(348);
obj.pushinQueue(637);
obj.pushinQueue(343);
obj.pop();
obj.pop();
obj.pop();
}
}
Result 1 :
348
Element 637 is pushed to Queue !
Elements in Queue :
18
67
343
203
348
637
Element 343 is pushed to Queue !
Elements in Queue :
18
67
343
203
348
637
343
Pop operation done !
Elements in Queue :
67
343
203
348
637
343
Pop operation done !
Elements in Queue :
343
203
348
637
343
Pop operation done !
Elements in Queue :
203
348
637
343
Program 2:
import java.util.Random;
public class InsertionSort {
public static void main(String str[]){
Random rand = new Random();
int arr[] = new int[20];
for(int i=0;i<20;i++){
arr[i]=rand.nextInt(100);
System.out.print(arr[i]+" ");
}
System.out.println("");
insertionSOrt(arr);
for(int i=0;i<20;i++){
System.out.println("arr["+i+"] : "+arr[i]);
}
}
public static void insertionSOrt(int arr[]){
for(int i=1;i=0 && temp
Solution
Program 1 :
public class QueueUsingArray {
private static final int queueCapacity = 20;
int arr[] = new int[queueCapacity];
int size = 0;
int top = -1;
int rear = 0;
public void pushinQueue(int pushedElement) {
if (top < queueCapacity - 1) {
top++;
arr[top] = pushedElement;
System.out.println("Element " + pushedElement
+ " is pushed to Queue !");
display();
} else {
System.out.println("Overflow !");
}
}
public void pop() {
if (top >= rear) {
rear++;
System.out.println("Pop operation done !");
display();
} else {
System.out.println("Underflow !");
}
}
public void display() {
if (top >= rear) {
System.out.println("Elements in Queue : ");
for (int i = rear; i <= top; i++) {
System.out.println(arr[i]);
}
}
}
public static void main(String[] args) {
QueueUsingArray obj = new QueueUsingArray();
obj.pop();
obj.pushinQueue(20);
obj.pushinQueue(18);
obj.pushinQueue(67);
obj.pushinQueue(343);
obj.pop();
obj.pushinQueue(203);
obj.pushinQueue(348);
obj.pushinQueue(637);
obj.pushinQueue(343);
obj.pop();
obj.pop();
obj.pop();
}
}
Result 1 :
348
Element 637 is pushed to Queue !
Elements in Queue :
18
67
343
203
348
637
Element 343 is pushed to Queue !
Elements in Queue :
18
67
343
203
348
637
343
Pop operation done !
Elements in Queue :
67
343
203
348
637
343
Pop operation done !
Elements in Queue :
343
203
348
637
343
Pop operation done !
Elements in Queue :
203
348
637
343
Program 2:
import java.util.Random;
public class InsertionSort {
public static void main(String str[]){
Random rand = new Random();
int arr[] = new int[20];
for(int i=0;i<20;i++){
arr[i]=rand.nextInt(100);
System.out.print(arr[i]+" ");
}
System.out.println("");
insertionSOrt(arr);
for(int i=0;i<20;i++){
System.out.println("arr["+i+"] : "+arr[i]);
}
}
public static void insertionSOrt(int arr[]){
for(int i=1;i=0 && temp

More Related Content

Similar to Program 1 public class QueueUsingArray { private static final i.pdf

Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.CIIT Atd.
 
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.CIIT Atd.
 
Im having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdfIm having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdfstopgolook
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfstopgolook
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfarihanthtoysandgifts
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfdeepua8
 
CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data StructuresSonia Pahuja
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docxkatherncarlyle
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2SIMONTHOMAS S
 

Similar to Program 1 public class QueueUsingArray { private static final i.pdf (20)

Stack array
Stack arrayStack array
Stack array
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.
 
java assignment
java assignmentjava assignment
java assignment
 
Im having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdfIm having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdf
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
 
Write the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdfWrite the program in MIPS that declares an array of positive integer.pdf
Write the program in MIPS that declares an array of positive integer.pdf
 
14 thread
14 thread14 thread
14 thread
 
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdfArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
ArrayTest.java import java.util.Arrays; import java.util.Scann.pdf
 
Stack
StackStack
Stack
 
CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data Structures
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
DS- Stack ADT
DS- Stack ADTDS- Stack ADT
DS- Stack ADT
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 

More from Ankitchhabra28

frequency tableSolution frequency table.pdf
 frequency tableSolution frequency table.pdf frequency tableSolution frequency table.pdf
frequency tableSolution frequency table.pdfAnkitchhabra28
 
ublic class Elevator { private static final String DOWN = down.pdf
  ublic class Elevator {     private static final String DOWN = down.pdf  ublic class Elevator {     private static final String DOWN = down.pdf
ublic class Elevator { private static final String DOWN = down.pdfAnkitchhabra28
 
[Al+] [OH-]^3 = Ksp0.2 [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf
[Al+]  [OH-]^3 = Ksp0.2  [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf[Al+]  [OH-]^3 = Ksp0.2  [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf
[Al+] [OH-]^3 = Ksp0.2 [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdfAnkitchhabra28
 
As a CFO environment of internal control needs to put in place t.pdf
    As a CFO environment of internal control needs to put in   place t.pdf    As a CFO environment of internal control needs to put in   place t.pdf
As a CFO environment of internal control needs to put in place t.pdfAnkitchhabra28
 
What are the financial markets and what purposes do they serveA f.pdf
What are the financial markets and what purposes do they serveA f.pdfWhat are the financial markets and what purposes do they serveA f.pdf
What are the financial markets and what purposes do they serveA f.pdfAnkitchhabra28
 
VI) Instruction set Architecture-      Instruction set is a colle.pdf
VI) Instruction set Architecture-      Instruction set is a colle.pdfVI) Instruction set Architecture-      Instruction set is a colle.pdf
VI) Instruction set Architecture-      Instruction set is a colle.pdfAnkitchhabra28
 
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdf
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdfThe OSI(Open System Interconnection) contains 7 layers.1.Physica.pdf
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdfAnkitchhabra28
 
the following statements are true Ubiquinone is a small, hydrophob.pdf
the following statements are true Ubiquinone is a small, hydrophob.pdfthe following statements are true Ubiquinone is a small, hydrophob.pdf
the following statements are true Ubiquinone is a small, hydrophob.pdfAnkitchhabra28
 
The evolution of one species is driven by the evolution of the other.pdf
The evolution of one species is driven by the evolution of the other.pdfThe evolution of one species is driven by the evolution of the other.pdf
The evolution of one species is driven by the evolution of the other.pdfAnkitchhabra28
 
Student choosed wrong subject. Question was not showning.Solutio.pdf
Student choosed wrong subject. Question was not showning.Solutio.pdfStudent choosed wrong subject. Question was not showning.Solutio.pdf
Student choosed wrong subject. Question was not showning.Solutio.pdfAnkitchhabra28
 
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdf
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdfS(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdf
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdfAnkitchhabra28
 
Question not visible..please post the imageSolutionQuestion no.pdf
Question not visible..please post the imageSolutionQuestion no.pdfQuestion not visible..please post the imageSolutionQuestion no.pdf
Question not visible..please post the imageSolutionQuestion no.pdfAnkitchhabra28
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfAnkitchhabra28
 
opps no format is there...Solutionopps no format is there....pdf
opps no format is there...Solutionopps no format is there....pdfopps no format is there...Solutionopps no format is there....pdf
opps no format is there...Solutionopps no format is there....pdfAnkitchhabra28
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
No, weight is not the measure of quantity of matter.Quantity of ma.pdf
No, weight is not the measure of quantity of matter.Quantity of ma.pdfNo, weight is not the measure of quantity of matter.Quantity of ma.pdf
No, weight is not the measure of quantity of matter.Quantity of ma.pdfAnkitchhabra28
 
Two. The pyruvate with carbons 4-6 will go throu.pdf
                     Two.  The pyruvate with carbons 4-6 will go throu.pdf                     Two.  The pyruvate with carbons 4-6 will go throu.pdf
Two. The pyruvate with carbons 4-6 will go throu.pdfAnkitchhabra28
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfAnkitchhabra28
 
is rightSolutionis right.pdf
is rightSolutionis right.pdfis rightSolutionis right.pdf
is rightSolutionis right.pdfAnkitchhabra28
 

More from Ankitchhabra28 (20)

frequency tableSolution frequency table.pdf
 frequency tableSolution frequency table.pdf frequency tableSolution frequency table.pdf
frequency tableSolution frequency table.pdf
 
ublic class Elevator { private static final String DOWN = down.pdf
  ublic class Elevator {     private static final String DOWN = down.pdf  ublic class Elevator {     private static final String DOWN = down.pdf
ublic class Elevator { private static final String DOWN = down.pdf
 
[Al+] [OH-]^3 = Ksp0.2 [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf
[Al+]  [OH-]^3 = Ksp0.2  [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf[Al+]  [OH-]^3 = Ksp0.2  [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf
[Al+] [OH-]^3 = Ksp0.2 [OH-]^3 = 210^-32[OH-] = 4.64210^-1.pdf
 
As a CFO environment of internal control needs to put in place t.pdf
    As a CFO environment of internal control needs to put in   place t.pdf    As a CFO environment of internal control needs to put in   place t.pdf
As a CFO environment of internal control needs to put in place t.pdf
 
What are the financial markets and what purposes do they serveA f.pdf
What are the financial markets and what purposes do they serveA f.pdfWhat are the financial markets and what purposes do they serveA f.pdf
What are the financial markets and what purposes do they serveA f.pdf
 
VI) Instruction set Architecture-      Instruction set is a colle.pdf
VI) Instruction set Architecture-      Instruction set is a colle.pdfVI) Instruction set Architecture-      Instruction set is a colle.pdf
VI) Instruction set Architecture-      Instruction set is a colle.pdf
 
waitSolutionwait.pdf
waitSolutionwait.pdfwaitSolutionwait.pdf
waitSolutionwait.pdf
 
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdf
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdfThe OSI(Open System Interconnection) contains 7 layers.1.Physica.pdf
The OSI(Open System Interconnection) contains 7 layers.1.Physica.pdf
 
the following statements are true Ubiquinone is a small, hydrophob.pdf
the following statements are true Ubiquinone is a small, hydrophob.pdfthe following statements are true Ubiquinone is a small, hydrophob.pdf
the following statements are true Ubiquinone is a small, hydrophob.pdf
 
The evolution of one species is driven by the evolution of the other.pdf
The evolution of one species is driven by the evolution of the other.pdfThe evolution of one species is driven by the evolution of the other.pdf
The evolution of one species is driven by the evolution of the other.pdf
 
Student choosed wrong subject. Question was not showning.Solutio.pdf
Student choosed wrong subject. Question was not showning.Solutio.pdfStudent choosed wrong subject. Question was not showning.Solutio.pdf
Student choosed wrong subject. Question was not showning.Solutio.pdf
 
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdf
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdfS(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdf
S(sulfur) atom Glucose molecule and compound Oxygen atom DN.pdf
 
Question not visible..please post the imageSolutionQuestion no.pdf
Question not visible..please post the imageSolutionQuestion no.pdfQuestion not visible..please post the imageSolutionQuestion no.pdf
Question not visible..please post the imageSolutionQuestion no.pdf
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
opps no format is there...Solutionopps no format is there....pdf
opps no format is there...Solutionopps no format is there....pdfopps no format is there...Solutionopps no format is there....pdf
opps no format is there...Solutionopps no format is there....pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
No, weight is not the measure of quantity of matter.Quantity of ma.pdf
No, weight is not the measure of quantity of matter.Quantity of ma.pdfNo, weight is not the measure of quantity of matter.Quantity of ma.pdf
No, weight is not the measure of quantity of matter.Quantity of ma.pdf
 
Two. The pyruvate with carbons 4-6 will go throu.pdf
                     Two.  The pyruvate with carbons 4-6 will go throu.pdf                     Two.  The pyruvate with carbons 4-6 will go throu.pdf
Two. The pyruvate with carbons 4-6 will go throu.pdf
 
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdfListing.javaimport java.util.Scanner;public class Listing {   .pdf
Listing.javaimport java.util.Scanner;public class Listing {   .pdf
 
is rightSolutionis right.pdf
is rightSolutionis right.pdfis rightSolutionis right.pdf
is rightSolutionis right.pdf
 

Recently uploaded

Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 

Recently uploaded (20)

Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 

Program 1 public class QueueUsingArray { private static final i.pdf

  • 1. Program 1 : public class QueueUsingArray { private static final int queueCapacity = 20; int arr[] = new int[queueCapacity]; int size = 0; int top = -1; int rear = 0; public void pushinQueue(int pushedElement) { if (top < queueCapacity - 1) { top++; arr[top] = pushedElement; System.out.println("Element " + pushedElement + " is pushed to Queue !"); display(); } else { System.out.println("Overflow !"); } } public void pop() { if (top >= rear) { rear++; System.out.println("Pop operation done !"); display(); } else { System.out.println("Underflow !"); } } public void display() { if (top >= rear) { System.out.println("Elements in Queue : "); for (int i = rear; i <= top; i++) { System.out.println(arr[i]); } } }
  • 2. public static void main(String[] args) { QueueUsingArray obj = new QueueUsingArray(); obj.pop(); obj.pushinQueue(20); obj.pushinQueue(18); obj.pushinQueue(67); obj.pushinQueue(343); obj.pop(); obj.pushinQueue(203); obj.pushinQueue(348); obj.pushinQueue(637); obj.pushinQueue(343); obj.pop(); obj.pop(); obj.pop(); } } Result 1 : 348 Element 637 is pushed to Queue ! Elements in Queue : 18 67 343 203 348 637 Element 343 is pushed to Queue ! Elements in Queue : 18 67 343 203 348 637 343
  • 3. Pop operation done ! Elements in Queue : 67 343 203 348 637 343 Pop operation done ! Elements in Queue : 343 203 348 637 343 Pop operation done ! Elements in Queue : 203 348 637 343 Program 2: import java.util.Random; public class InsertionSort { public static void main(String str[]){ Random rand = new Random(); int arr[] = new int[20]; for(int i=0;i<20;i++){ arr[i]=rand.nextInt(100); System.out.print(arr[i]+" "); } System.out.println(""); insertionSOrt(arr); for(int i=0;i<20;i++){ System.out.println("arr["+i+"] : "+arr[i]); }
  • 4. } public static void insertionSOrt(int arr[]){ for(int i=1;i=0 && temp Solution Program 1 : public class QueueUsingArray { private static final int queueCapacity = 20; int arr[] = new int[queueCapacity]; int size = 0; int top = -1; int rear = 0; public void pushinQueue(int pushedElement) { if (top < queueCapacity - 1) { top++; arr[top] = pushedElement; System.out.println("Element " + pushedElement + " is pushed to Queue !"); display(); } else { System.out.println("Overflow !"); } } public void pop() { if (top >= rear) { rear++; System.out.println("Pop operation done !"); display(); } else { System.out.println("Underflow !"); } } public void display() { if (top >= rear) { System.out.println("Elements in Queue : "); for (int i = rear; i <= top; i++) {
  • 5. System.out.println(arr[i]); } } } public static void main(String[] args) { QueueUsingArray obj = new QueueUsingArray(); obj.pop(); obj.pushinQueue(20); obj.pushinQueue(18); obj.pushinQueue(67); obj.pushinQueue(343); obj.pop(); obj.pushinQueue(203); obj.pushinQueue(348); obj.pushinQueue(637); obj.pushinQueue(343); obj.pop(); obj.pop(); obj.pop(); } } Result 1 : 348 Element 637 is pushed to Queue ! Elements in Queue : 18 67 343 203 348 637 Element 343 is pushed to Queue ! Elements in Queue : 18 67 343
  • 6. 203 348 637 343 Pop operation done ! Elements in Queue : 67 343 203 348 637 343 Pop operation done ! Elements in Queue : 343 203 348 637 343 Pop operation done ! Elements in Queue : 203 348 637 343 Program 2: import java.util.Random; public class InsertionSort { public static void main(String str[]){ Random rand = new Random(); int arr[] = new int[20]; for(int i=0;i<20;i++){ arr[i]=rand.nextInt(100); System.out.print(arr[i]+" "); } System.out.println("");
  • 7. insertionSOrt(arr); for(int i=0;i<20;i++){ System.out.println("arr["+i+"] : "+arr[i]); } } public static void insertionSOrt(int arr[]){ for(int i=1;i=0 && temp