Похожие чаты

#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 ответов

287 просмотров
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

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта