Похожие чаты

#Include <bits/stdc++.h> using namespace std; class leafN{ public:

char ch;
int fq;
leafN(char c, int f){
ch = c;
fq = f;
}
~leafN(){
delete this;
}
};

int main(){
priority_queue<int> pq;
cout << "Enter the number of characters\n";
int n;
cin>>n;
leafN *leaf[n];
cout << "Enter the character and its frequency \n";
for(int i=0; i<n; i++){
int a,w;
cin>>a>>w;
leaf[i] = new leafN(a,w);
}
for(int i=0; i<n; i++){
cout << leaf[i]->ch << " " << leaf[i]->fq << endl;
}
} Please help, why this doesn't work?

18 ответов

294 просмотра
none- Автор вопроса

it's not taking in n inputs into leaf pointer array

hmm. don't use bits/stdc++ header. it's honestly annoying for everyone else who doesn't do competitive programming, not to mention it is a bad habit

none- Автор вопроса
Manav | avoid unnecessary messaging me
hmm. don't use bits/stdc++ header. it's honestly a...

Any visible error in my code or is it due to the <bits/stdc++.h> library?

Is it ok to use delete this?🤨

nope, it shouldn't be a problem. I am running it to see what actually happens, wait for me or other members to respond

You get input as int a but you use it as a char in your constructor?

Delete each by a loop Don't use delete this

none- Автор вопроса
none- Автор вопроса
Prince Of Persia [field = CE,DM = BLOCK]
Delete each by a loop Don't use delete this

i don't want to delete the data, I put a destructor only for formality

Prince Of Persia [field = CE,DM = BLOCK]
That destructor shouldn't do anything

I just don't see any need for anything to be done in destructor But you have to delete each variable in the array with a loop

hmm.. there's a few things that are very wrong about your code: 1. What is leafN supposed to be? Are you modelling a tree structure? 2. Why do you allocate individual leafs in the for loop? Why not just allocate it outside the for loop? ah it's an array of pointers nvm :)

none- Автор вопроса
Manav | avoid unnecessary messaging me
hmm.. there's a few things that are very wrong abo...

Yes, kind of tree. Actually it's an incomplete code, i was trying to implement huffman tree

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта