SlideShare a Scribd company logo
1 of 2
NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE. ASAP! 
21. Write a function to perform QuickSort algorithm. Make sure to write any other functions (i.e.
partition, swap, etc.) needed to execute the quick sort.
22. Write a function to implement either the MergeSort or HeapSort sorting algorithm. Just like
with the quicksort, make sure you write any other functions needed to execute the sorting
algorithm of your choice.
23. Write a function that will insert a new key into a binary search tree. Assume that the function
takes two parameters: root and newValue, where root is the root of the binary search tree and
newValue is the new key to be inserted into the binary tree.
Solution
#include #include int a[10],l,u,i,j; void quick(int *,int,int); void main() { clrscr(); cout <<"enter
10 elements"; for(i=0;i<10;i++) cin >> a[i]; l=0; u=9; quick(a,l,u); cout <<"sorted elements";
for(i=0;i<10;i++) cout << a[i] << " "; getch(); } void quick(int a[],int l,int u) { int p,temp; if(l p
&& i<=j ) j--; if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp;} } temp=a[j]; a[j]=a[l]; a[l]=temp; cout
<<" "; for(i=0;i<10;i++) cout < #include using namespace std; void max_heapify(int *a, int i,
int n) { int j, temp; temp = a[i]; j = 2*i; while (j <= n) { if (j < n && a[j+1] > a[j]) j = j+1; if
(temp > a[j]) break; else if (temp <= a[j]) { a[j/2] = a[j]; j = 2*j; } } a[j/2] = temp; return; } void
heapsort(int *a, int n) { int i, temp; for (i = n; i >= 2; i--) { temp = a[i]; a[i] = a[1]; a[1] = temp;
max_heapify(a, 1, i - 1); } } void build_maxheap(int *a, int n) { int i; for(i = n/2; i >= 1; i--) {
max_heapify(a, i, n); } } int main() { int n, i, x; cout<<"enter no of elements of array ";
cin>>n; int a[20]; for (i = 1; i <= n; i++) { cout<<"enter element"<<(i)< >a[i]; }
build_maxheap(a,n); heapsort(a, n); cout<<"sorted output "; for (i = 1; i <= n; i++) { cout<
NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE- ASAP! -- 21- Write a.docx

More Related Content

Similar to NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE- ASAP! -- 21- Write a.docx

Similar to NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE- ASAP! -- 21- Write a.docx (20)

Lập trình C
Lập trình CLập trình C
Lập trình C
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Array Cont
Array ContArray Cont
Array Cont
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
y Bookmarks People Window Helo Online Derivative edusubmi tionassig.docx
 y Bookmarks People Window Helo Online Derivative edusubmi tionassig.docx y Bookmarks People Window Helo Online Derivative edusubmi tionassig.docx
y Bookmarks People Window Helo Online Derivative edusubmi tionassig.docx
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 

More from scroghamtressie

Name four services that might allow you to control a VM in an IaaS env.docx
Name four services that might allow you to control a VM in an IaaS env.docxName four services that might allow you to control a VM in an IaaS env.docx
Name four services that might allow you to control a VM in an IaaS env.docxscroghamtressie
 
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docx
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docxmus101 What musical techniques did Vivaldi use in La Primavera to depi.docx
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docxscroghamtressie
 
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docx
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docxMust every revolution end in tyranny (as suggested by Ignazio Silone)-.docx
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docxscroghamtressie
 
Multiple Choice Question The information in the following table is fro.docx
Multiple Choice Question The information in the following table is fro.docxMultiple Choice Question The information in the following table is fro.docx
Multiple Choice Question The information in the following table is fro.docxscroghamtressie
 
Mips assembly language Generate the quadruples for the program code fr.docx
Mips assembly language Generate the quadruples for the program code fr.docxMips assembly language Generate the quadruples for the program code fr.docx
Mips assembly language Generate the quadruples for the program code fr.docxscroghamtressie
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxscroghamtressie
 
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxMerge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxscroghamtressie
 
Match the words in the left column to the appropriate blanks in the se.docx
Match the words in the left column to the appropriate blanks in the se.docxMatch the words in the left column to the appropriate blanks in the se.docx
Match the words in the left column to the appropriate blanks in the se.docxscroghamtressie
 
Nathanson Corporation was organized on May 1- 2014- The following even.docx
Nathanson Corporation was organized on May 1- 2014- The following even.docxNathanson Corporation was organized on May 1- 2014- The following even.docx
Nathanson Corporation was organized on May 1- 2014- The following even.docxscroghamtressie
 
Match the following aqueous solutions with the appropriate letter from (4).docx
Match the following aqueous solutions with the appropriate letter from (4).docxMatch the following aqueous solutions with the appropriate letter from (4).docx
Match the following aqueous solutions with the appropriate letter from (4).docxscroghamtressie
 

More from scroghamtressie (10)

Name four services that might allow you to control a VM in an IaaS env.docx
Name four services that might allow you to control a VM in an IaaS env.docxName four services that might allow you to control a VM in an IaaS env.docx
Name four services that might allow you to control a VM in an IaaS env.docx
 
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docx
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docxmus101 What musical techniques did Vivaldi use in La Primavera to depi.docx
mus101 What musical techniques did Vivaldi use in La Primavera to depi.docx
 
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docx
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docxMust every revolution end in tyranny (as suggested by Ignazio Silone)-.docx
Must every revolution end in tyranny (as suggested by Ignazio Silone)-.docx
 
Multiple Choice Question The information in the following table is fro.docx
Multiple Choice Question The information in the following table is fro.docxMultiple Choice Question The information in the following table is fro.docx
Multiple Choice Question The information in the following table is fro.docx
 
Mips assembly language Generate the quadruples for the program code fr.docx
Mips assembly language Generate the quadruples for the program code fr.docxMips assembly language Generate the quadruples for the program code fr.docx
Mips assembly language Generate the quadruples for the program code fr.docx
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
 
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxMerge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
 
Match the words in the left column to the appropriate blanks in the se.docx
Match the words in the left column to the appropriate blanks in the se.docxMatch the words in the left column to the appropriate blanks in the se.docx
Match the words in the left column to the appropriate blanks in the se.docx
 
Nathanson Corporation was organized on May 1- 2014- The following even.docx
Nathanson Corporation was organized on May 1- 2014- The following even.docxNathanson Corporation was organized on May 1- 2014- The following even.docx
Nathanson Corporation was organized on May 1- 2014- The following even.docx
 
Match the following aqueous solutions with the appropriate letter from (4).docx
Match the following aqueous solutions with the appropriate letter from (4).docxMatch the following aqueous solutions with the appropriate letter from (4).docx
Match the following aqueous solutions with the appropriate letter from (4).docx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE- ASAP! -- 21- Write a.docx

  • 1. NEED THIS PROGRAMS IN C++ AND WITH COMPLETE CODE. ASAP! 21. Write a function to perform QuickSort algorithm. Make sure to write any other functions (i.e. partition, swap, etc.) needed to execute the quick sort. 22. Write a function to implement either the MergeSort or HeapSort sorting algorithm. Just like with the quicksort, make sure you write any other functions needed to execute the sorting algorithm of your choice. 23. Write a function that will insert a new key into a binary search tree. Assume that the function takes two parameters: root and newValue, where root is the root of the binary search tree and newValue is the new key to be inserted into the binary tree. Solution #include #include int a[10],l,u,i,j; void quick(int *,int,int); void main() { clrscr(); cout <<"enter 10 elements"; for(i=0;i<10;i++) cin >> a[i]; l=0; u=9; quick(a,l,u); cout <<"sorted elements"; for(i=0;i<10;i++) cout << a[i] << " "; getch(); } void quick(int a[],int l,int u) { int p,temp; if(l p && i<=j ) j--; if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp;} } temp=a[j]; a[j]=a[l]; a[l]=temp; cout <<" "; for(i=0;i<10;i++) cout < #include using namespace std; void max_heapify(int *a, int i, int n) { int j, temp; temp = a[i]; j = 2*i; while (j <= n) { if (j < n && a[j+1] > a[j]) j = j+1; if (temp > a[j]) break; else if (temp <= a[j]) { a[j/2] = a[j]; j = 2*j; } } a[j/2] = temp; return; } void heapsort(int *a, int n) { int i, temp; for (i = n; i >= 2; i--) { temp = a[i]; a[i] = a[1]; a[1] = temp; max_heapify(a, 1, i - 1); } } void build_maxheap(int *a, int n) { int i; for(i = n/2; i >= 1; i--) { max_heapify(a, i, n); } } int main() { int n, i, x; cout<<"enter no of elements of array "; cin>>n; int a[20]; for (i = 1; i <= n; i++) { cout<<"enter element"<<(i)< >a[i]; } build_maxheap(a,n); heapsort(a, n); cout<<"sorted output "; for (i = 1; i <= n; i++) { cout<