SlideShare a Scribd company logo
1 of 5
1- please help me to solve this program, the extended this code to add the function for
deleting minimum or maximum values is not working properly, please correct it along with
its main function and correct output.
#include <stdio.h>
void swap(int a[], int n1, int n2) {
int temp = a[n1];
a[n1] = a[n2];
a[n2] = temp;
}
int get_parent(int n) {
if (!(n % 4)) return (n - 4) / 2;
if (!(n % 2)) return (n - 2) / 2;
if (((n - 1) % 4)) return (n - 3) / 2;
else return (n - 1) / 2;
}
void heapify_max(int a[], int n) {
int parent = get_parent(n);
while (n > 1 && a[n] > a[parent]) {
swap(a, n, parent);
n = parent;
parent = get_parent(n);
}
}
void heapify_min(int a[], int n) {
int parent = get_parent(n);
while (n > 0 && a[n] < a[parent]) {
swap(a, n, parent);
n = parent;
parent = get_parent(n);
}
}
void insert_intervalheap(int a[], int *pos, int val) {
int n = *pos, parent, parent1;
(*pos)++;
a[n] = val;
if (n == 0) return;
if (n == 1) {
if (a[0] > a[1]) swap(a, 0, 1);
return;
}
if (!(n % 2)) {
parent = get_parent(n);
} else {
parent1 = get_parent(n) + 1;
if (a[n] < a[parent]) {
swap(a, n, parent);
heapify_min(a, parent);
}
if (a[n] > a[parent1]) {
swap(a, n, parent1);
heapify_max(a, parent1);
}
}
}
int get_min(int a[], int n)
{
return (a[0]);
}
int get_max(int a[], int n) {
if (n > 1) {
return (a[1]);
} else {
return (a[0]);
}
}
int delete_min(int a[], int *pos) {
if (*pos == 0) {
printf("Interval heap is empty. Cannot delete minimum value.n");
return -1;
}
int min = a[0];
*pos -= 1;
a[0] = a[*pos];
heapify_min(a, 0);
return min;
}
int delete_max(int a[], int *pos) {
if (*pos == 0) {
printf("Interval heap is empty. Cannot delete maximum value.n");
return -1;
}
int max = a[1];
*pos -= 1;
a[1] = a[*pos];
heapify_max(a, 1);
return max;
}
int main() {
int i, interval_heap[100], n = 0;
while (1) {
printf("n Enter any positive value to insert in interval heap and negative number to stop: ");
scanf("%d", &i);
if (i < 0) break;
insert_intervalheap(interval_heap, &n, i);
printf("nTotal elements in Interval Heap=%dnMinimum-%dnMaximum-%d", n,
get_min(interval_heap, n), get_max(interval_heap, n));
}
return 0;
}
2- Please send me the complete code for Huffman Coding using the bitwise operator and its
main functions.
#include <iostream>
#include <queue>
#include <unordered_map>
#include <bitset>
using namespace std;
// Tree node for Huffman coding
struct HuffmanNode {
char data;
int freq;
HuffmanNode *left, *right;
HuffmanNode(char data, int freq) {
this->data = data;
this->freq = freq;
left = right = NULL;
}
};
struct Compare {
bool operator()(HuffmanNode* a, HuffmanNode* b) {
return a->freq > b->freq;
}
};
void generateCodes(HuffmanNode* root, string code, unordered_map<char, string>& codes) {
if (root == NULL) return;
if (root->data != '0') {
codes[root->data] = code;
}
generateCodes(root->left, code + '0', codes);
generateCodes(root->right, code + '1', codes);
}
unordered_map<char, string> buildHuffmanTree(string text) {
unordered_map<char, int> freqMap;
for (char c : text) {
freqMap[c]++;
}
priority_queue<HuffmanNode*, vector<HuffmanNode*>, Compare> pq;
for (auto& p : freqMap) {
pq.push(new HuffmanNode(p.first, p.second));
}
while (pq.size() > 1) {
HuffmanNode* left = pq.top();
pq.pop();
HuffmanNode* right = pq.top();
pq.pop();
HuffmanNode* parent = new HuffmanNode('0', left->freq + right->freq);
parent->left = left;
parent->right = right;
pq.push(parent);
}
unordered_map<char, string> codes;
generateCodes(pq.top(), "", codes);
return codes;
}
// Encodes the text using the generated Huffman codes
string huffmanEncode(string text, unordered_map<char, string>& codes) {
string encodedText = "";
for (char c : text) {
encodedText += codes[c];
}
return encodedText;
}
// Decodes the Huffman-encoded text using the generated Huffman codes
string huffmanDecode(string encodedText, unordered_map<char, string>& codes) {
string decodedText = "";
int i = 0;
while (i < encodedText.size()) {
HuffmanNode* node = codes.begin()->second[0] == '0' ? codes.begin()->second[1] == '0' ?
codes.begin()->second[2] == '0' ? codes.begin()->second[3] == '0' ?
codes.begin()->second[4] == '0' ? codes.begin()->second[5] == '0' ? codes.begin()->second[6]
== '0' ? codes.begin()->second[7] == '0' ? codes.begin()->second[8] == '0' ?
codes.begin()->second[9] == '0' ? codes.begin()->second[10] == '0' ? codes.begin()->second[11]
== '0' ? codes.begin()->second[12] == '0' ? codes.begin()->second[13] == '0' ?
codes.begin()->second[14] == '0' ? codes.begin()->second[15] == '0' ? node->left : node->right :
codes.begin()->second[15] == '0' ?
node->left : node->right : codes.begin

More Related Content

Similar to 1- please help me to solve this program- the extended this code to add.docx

Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementSreedhar Chowdam
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfMuhammadMaazShaik
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
Write a program to implement and test the following sorting algorithm.docx
 Write a program to implement and test the following sorting algorithm.docx Write a program to implement and test the following sorting algorithm.docx
Write a program to implement and test the following sorting algorithm.docxajoy21
 

Similar to 1- please help me to solve this program- the extended this code to add.docx (20)

week-17x
week-17xweek-17x
week-17x
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
Ada file
Ada fileAda file
Ada file
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
7 functions
7  functions7  functions
7 functions
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
week-4x
week-4xweek-4x
week-4x
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Write a program to implement and test the following sorting algorithm.docx
 Write a program to implement and test the following sorting algorithm.docx Write a program to implement and test the following sorting algorithm.docx
Write a program to implement and test the following sorting algorithm.docx
 

More from EvandWyBurgesss

10- How would periods of drought affect a climatogram- 10- How would.docx
10- How would periods of drought affect a climatogram-  10- How would.docx10- How would periods of drought affect a climatogram-  10- How would.docx
10- How would periods of drought affect a climatogram- 10- How would.docxEvandWyBurgesss
 
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docxEvandWyBurgesss
 
10- questions- What should be the cardinality notation next to the PRO.docx
10- questions- What should be the cardinality notation next to the PRO.docx10- questions- What should be the cardinality notation next to the PRO.docx
10- questions- What should be the cardinality notation next to the PRO.docxEvandWyBurgesss
 
10- Describe the cardiovascular system in birds and mammals- Describe.docx
10- Describe the cardiovascular system in birds and mammals- Describe.docx10- Describe the cardiovascular system in birds and mammals- Describe.docx
10- Describe the cardiovascular system in birds and mammals- Describe.docxEvandWyBurgesss
 
10- Art allows viewers or artists to look inwards- To explore themselv.docx
10- Art allows viewers or artists to look inwards- To explore themselv.docx10- Art allows viewers or artists to look inwards- To explore themselv.docx
10- Art allows viewers or artists to look inwards- To explore themselv.docxEvandWyBurgesss
 
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docxEvandWyBurgesss
 
10- Based on the statistics reported in the slide in the Infection Tem.docx
10- Based on the statistics reported in the slide in the Infection Tem.docx10- Based on the statistics reported in the slide in the Infection Tem.docx
10- Based on the statistics reported in the slide in the Infection Tem.docxEvandWyBurgesss
 
10- a) Let L1-{01} than find out the strings for another language L2 s.docx
10- a) Let L1-{01} than find out the strings for another language L2 s.docx10- a) Let L1-{01} than find out the strings for another language L2 s.docx
10- a) Let L1-{01} than find out the strings for another language L2 s.docxEvandWyBurgesss
 
10 points What is a proxy- the selling of a corporation's stock on the.docx
10 points What is a proxy- the selling of a corporation's stock on the.docx10 points What is a proxy- the selling of a corporation's stock on the.docx
10 points What is a proxy- the selling of a corporation's stock on the.docxEvandWyBurgesss
 
10 Soints Consider the following Table- summarizine the number of hour.docx
10 Soints Consider the following Table- summarizine the number of hour.docx10 Soints Consider the following Table- summarizine the number of hour.docx
10 Soints Consider the following Table- summarizine the number of hour.docxEvandWyBurgesss
 
1-What role does interest group information play in policymaking- What.docx
1-What role does interest group information play in policymaking- What.docx1-What role does interest group information play in policymaking- What.docx
1-What role does interest group information play in policymaking- What.docxEvandWyBurgesss
 
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docxEvandWyBurgesss
 
1-Racial classification based on biological traits is arbitrary and su.docx
1-Racial classification based on biological traits is arbitrary and su.docx1-Racial classification based on biological traits is arbitrary and su.docx
1-Racial classification based on biological traits is arbitrary and su.docxEvandWyBurgesss
 
1-The five parts of the Porter Five Forces framework include the follo.docx
1-The five parts of the Porter Five Forces framework include the follo.docx1-The five parts of the Porter Five Forces framework include the follo.docx
1-The five parts of the Porter Five Forces framework include the follo.docxEvandWyBurgesss
 
1-Explain the difference between using (i) selective media and conditi.docx
1-Explain the difference between using (i) selective media and conditi.docx1-Explain the difference between using (i) selective media and conditi.docx
1-Explain the difference between using (i) selective media and conditi.docxEvandWyBurgesss
 
1-Every year- the students at a school are given a musical aptitude te.docx
1-Every year- the students at a school are given a musical aptitude te.docx1-Every year- the students at a school are given a musical aptitude te.docx
1-Every year- the students at a school are given a musical aptitude te.docxEvandWyBurgesss
 
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docxEvandWyBurgesss
 
1-Country A and Country B have the same number of resources- Country A.docx
1-Country A and Country B have the same number of resources- Country A.docx1-Country A and Country B have the same number of resources- Country A.docx
1-Country A and Country B have the same number of resources- Country A.docxEvandWyBurgesss
 
1-1Match each of the options above to the items below.docx
1-1Match each of the options above to the items below.docx1-1Match each of the options above to the items below.docx
1-1Match each of the options above to the items below.docxEvandWyBurgesss
 
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docxEvandWyBurgesss
 

More from EvandWyBurgesss (20)

10- How would periods of drought affect a climatogram- 10- How would.docx
10- How would periods of drought affect a climatogram-  10- How would.docx10- How would periods of drought affect a climatogram-  10- How would.docx
10- How would periods of drought affect a climatogram- 10- How would.docx
 
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx
10- The bands and stripes on Jupiter- Satum and Neptune are common to.docx
 
10- questions- What should be the cardinality notation next to the PRO.docx
10- questions- What should be the cardinality notation next to the PRO.docx10- questions- What should be the cardinality notation next to the PRO.docx
10- questions- What should be the cardinality notation next to the PRO.docx
 
10- Describe the cardiovascular system in birds and mammals- Describe.docx
10- Describe the cardiovascular system in birds and mammals- Describe.docx10- Describe the cardiovascular system in birds and mammals- Describe.docx
10- Describe the cardiovascular system in birds and mammals- Describe.docx
 
10- Art allows viewers or artists to look inwards- To explore themselv.docx
10- Art allows viewers or artists to look inwards- To explore themselv.docx10- Art allows viewers or artists to look inwards- To explore themselv.docx
10- Art allows viewers or artists to look inwards- To explore themselv.docx
 
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx
10- Eukaryotes - Protists- Complete the table below- Some of the answe.docx
 
10- Based on the statistics reported in the slide in the Infection Tem.docx
10- Based on the statistics reported in the slide in the Infection Tem.docx10- Based on the statistics reported in the slide in the Infection Tem.docx
10- Based on the statistics reported in the slide in the Infection Tem.docx
 
10- a) Let L1-{01} than find out the strings for another language L2 s.docx
10- a) Let L1-{01} than find out the strings for another language L2 s.docx10- a) Let L1-{01} than find out the strings for another language L2 s.docx
10- a) Let L1-{01} than find out the strings for another language L2 s.docx
 
10 points What is a proxy- the selling of a corporation's stock on the.docx
10 points What is a proxy- the selling of a corporation's stock on the.docx10 points What is a proxy- the selling of a corporation's stock on the.docx
10 points What is a proxy- the selling of a corporation's stock on the.docx
 
10 Soints Consider the following Table- summarizine the number of hour.docx
10 Soints Consider the following Table- summarizine the number of hour.docx10 Soints Consider the following Table- summarizine the number of hour.docx
10 Soints Consider the following Table- summarizine the number of hour.docx
 
1-What role does interest group information play in policymaking- What.docx
1-What role does interest group information play in policymaking- What.docx1-What role does interest group information play in policymaking- What.docx
1-What role does interest group information play in policymaking- What.docx
 
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx
1-What is the pH of lake Lanier GA-- if contains -H+--0-000001 (5 P).docx
 
1-Racial classification based on biological traits is arbitrary and su.docx
1-Racial classification based on biological traits is arbitrary and su.docx1-Racial classification based on biological traits is arbitrary and su.docx
1-Racial classification based on biological traits is arbitrary and su.docx
 
1-The five parts of the Porter Five Forces framework include the follo.docx
1-The five parts of the Porter Five Forces framework include the follo.docx1-The five parts of the Porter Five Forces framework include the follo.docx
1-The five parts of the Porter Five Forces framework include the follo.docx
 
1-Explain the difference between using (i) selective media and conditi.docx
1-Explain the difference between using (i) selective media and conditi.docx1-Explain the difference between using (i) selective media and conditi.docx
1-Explain the difference between using (i) selective media and conditi.docx
 
1-Every year- the students at a school are given a musical aptitude te.docx
1-Every year- the students at a school are given a musical aptitude te.docx1-Every year- the students at a school are given a musical aptitude te.docx
1-Every year- the students at a school are given a musical aptitude te.docx
 
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx
1-Increased usage of smartphone- In the past 10 years- the usage of sm.docx
 
1-Country A and Country B have the same number of resources- Country A.docx
1-Country A and Country B have the same number of resources- Country A.docx1-Country A and Country B have the same number of resources- Country A.docx
1-Country A and Country B have the same number of resources- Country A.docx
 
1-1Match each of the options above to the items below.docx
1-1Match each of the options above to the items below.docx1-1Match each of the options above to the items below.docx
1-1Match each of the options above to the items below.docx
 
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx
1-4) Match the term to the most appropriate example (A-D) A) When a ge.docx
 

Recently uploaded

How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
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
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIagpharmacy11
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfAlexander Litvinenko
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
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
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024CapitolTechU
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Celine George
 
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
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxsbabel
 

Recently uploaded (20)

How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
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
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
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...
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptx
 

1- please help me to solve this program- the extended this code to add.docx

  • 1. 1- please help me to solve this program, the extended this code to add the function for deleting minimum or maximum values is not working properly, please correct it along with its main function and correct output. #include <stdio.h> void swap(int a[], int n1, int n2) { int temp = a[n1]; a[n1] = a[n2]; a[n2] = temp; } int get_parent(int n) { if (!(n % 4)) return (n - 4) / 2; if (!(n % 2)) return (n - 2) / 2; if (((n - 1) % 4)) return (n - 3) / 2; else return (n - 1) / 2; } void heapify_max(int a[], int n) { int parent = get_parent(n); while (n > 1 && a[n] > a[parent]) { swap(a, n, parent); n = parent; parent = get_parent(n); } } void heapify_min(int a[], int n) { int parent = get_parent(n); while (n > 0 && a[n] < a[parent]) { swap(a, n, parent); n = parent; parent = get_parent(n); } } void insert_intervalheap(int a[], int *pos, int val) { int n = *pos, parent, parent1; (*pos)++; a[n] = val; if (n == 0) return; if (n == 1) { if (a[0] > a[1]) swap(a, 0, 1); return; }
  • 2. if (!(n % 2)) { parent = get_parent(n); } else { parent1 = get_parent(n) + 1; if (a[n] < a[parent]) { swap(a, n, parent); heapify_min(a, parent); } if (a[n] > a[parent1]) { swap(a, n, parent1); heapify_max(a, parent1); } } } int get_min(int a[], int n) { return (a[0]); } int get_max(int a[], int n) { if (n > 1) { return (a[1]); } else { return (a[0]); } } int delete_min(int a[], int *pos) { if (*pos == 0) { printf("Interval heap is empty. Cannot delete minimum value.n"); return -1; } int min = a[0]; *pos -= 1; a[0] = a[*pos]; heapify_min(a, 0); return min; } int delete_max(int a[], int *pos) { if (*pos == 0) { printf("Interval heap is empty. Cannot delete maximum value.n"); return -1; } int max = a[1];
  • 3. *pos -= 1; a[1] = a[*pos]; heapify_max(a, 1); return max; } int main() { int i, interval_heap[100], n = 0; while (1) { printf("n Enter any positive value to insert in interval heap and negative number to stop: "); scanf("%d", &i); if (i < 0) break; insert_intervalheap(interval_heap, &n, i); printf("nTotal elements in Interval Heap=%dnMinimum-%dnMaximum-%d", n, get_min(interval_heap, n), get_max(interval_heap, n)); } return 0; } 2- Please send me the complete code for Huffman Coding using the bitwise operator and its main functions. #include <iostream> #include <queue> #include <unordered_map> #include <bitset> using namespace std; // Tree node for Huffman coding struct HuffmanNode { char data; int freq; HuffmanNode *left, *right; HuffmanNode(char data, int freq) { this->data = data; this->freq = freq; left = right = NULL; } }; struct Compare { bool operator()(HuffmanNode* a, HuffmanNode* b) { return a->freq > b->freq; } };
  • 4. void generateCodes(HuffmanNode* root, string code, unordered_map<char, string>& codes) { if (root == NULL) return; if (root->data != '0') { codes[root->data] = code; } generateCodes(root->left, code + '0', codes); generateCodes(root->right, code + '1', codes); } unordered_map<char, string> buildHuffmanTree(string text) { unordered_map<char, int> freqMap; for (char c : text) { freqMap[c]++; } priority_queue<HuffmanNode*, vector<HuffmanNode*>, Compare> pq; for (auto& p : freqMap) { pq.push(new HuffmanNode(p.first, p.second)); } while (pq.size() > 1) { HuffmanNode* left = pq.top(); pq.pop(); HuffmanNode* right = pq.top(); pq.pop(); HuffmanNode* parent = new HuffmanNode('0', left->freq + right->freq); parent->left = left; parent->right = right; pq.push(parent); } unordered_map<char, string> codes; generateCodes(pq.top(), "", codes); return codes; } // Encodes the text using the generated Huffman codes string huffmanEncode(string text, unordered_map<char, string>& codes) { string encodedText = ""; for (char c : text) { encodedText += codes[c]; } return encodedText; } // Decodes the Huffman-encoded text using the generated Huffman codes string huffmanDecode(string encodedText, unordered_map<char, string>& codes) {
  • 5. string decodedText = ""; int i = 0; while (i < encodedText.size()) { HuffmanNode* node = codes.begin()->second[0] == '0' ? codes.begin()->second[1] == '0' ? codes.begin()->second[2] == '0' ? codes.begin()->second[3] == '0' ? codes.begin()->second[4] == '0' ? codes.begin()->second[5] == '0' ? codes.begin()->second[6] == '0' ? codes.begin()->second[7] == '0' ? codes.begin()->second[8] == '0' ? codes.begin()->second[9] == '0' ? codes.begin()->second[10] == '0' ? codes.begin()->second[11] == '0' ? codes.begin()->second[12] == '0' ? codes.begin()->second[13] == '0' ? codes.begin()->second[14] == '0' ? codes.begin()->second[15] == '0' ? node->left : node->right : codes.begin()->second[15] == '0' ? node->left : node->right : codes.begin