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-18x
week-18xweek-18x
week-18x
 
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

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Recently uploaded (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

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