Bir kod ekinde bir C++ kodu yazmaya çalışıyorum, ancak bu kodun, bir soneki ya da alt dizinin son eklenme sırasında görünen sıklıklarının her bir düğümdeki sayaçlarını takip etmesini istiyorum: sadece 4 karakterden A, C, G ve TSuffix Trie in C++
aşağıdaki kod benim girişimi ancak olduğu ile çalışıyorum o düzgün çalışmıyor onun:
#include<iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
struct SuffixTreeNode{
char c;
struct SuffixTreeNode* one;
struct SuffixTreeNode* two;
struct SuffixTreeNode* three;
struct SuffixTreeNode* four;
//int count;
};
SuffixTreeNode* CreateNode(char ch){
SuffixTreeNode* newnode=new SuffixTreeNode();
newnode->c=ch;
newnode->one=NULL;
newnode->two=NULL;
newnode->three=NULL;
newnode->four=NULL;
//count=0;
}
SuffixTreeNode* Insert(SuffixTreeNode* root,char ch){
if (root==NULL){
root=CreateNode(ch);
}
else if(ch=='a'){
root->one=Insert(root->one,ch);
}
else if(ch=='c'){
root->two=Insert(root->two,ch);
}
else if(ch=='g'){
root->three=Insert(root->three,ch);
}
else if(ch=='t') {
root->four=Insert(root->four,ch);
}
return root;
}
bool Search(SuffixTreeNode* root, int data){
if(root==NULL) return false;
else if (root->c==data) return true;
else if (root->c=='a')return Search(root->one,data);
else if (root->c=='c')return Search(root->two,data);
else if (root->c=='g')return Search(root->three,data);
else return Search(root->four,data);
}
int main(){
SuffixTreeNode* root=NULL;
char str;
root=Insert(root,'a');
root=Insert(root,'c');
root=Insert(root,'c');
root=Insert(root,'t');
root=Insert(root,'a');
root=Insert(root,'g');
cout<<"Enter character to be searched\n";
cin>>str;
if(Search(root,str)==true)cout<<"Found\n";
else cout<<"Not found\n";
}
Ve C etiketi kaymış, değil mi? Alakasız, ** farklı ** diller için etiket eklemeyin. – Olaf
Frankly 'C++' etiketi indirilmelidir. Bu C++ değil ... Neden başlıkların c ve C++ sürümlerini dahil ediyorsunuz? Ayrıca gerçekten c veya C++ ister misin? Nesneleri kullanmak için yalvarır. Ayrıca daha genel bir notta. Bir sorum yok. "Burada benimki kırık, hata ayıkla" ve bu madde dışında konu dışı kabul edilir: "* Hata ayıklama yardımını arayan sorular (" neden bu kod çalışmıyor? ") Istenen davranışı, belirli bir özelliği içermelidir Sorunun ya da hatanın ve soruyu kendi içinde yeniden üretmek için gereken en kısa kod. * "Öyleyse, başkalarının size yardım etmesine yardım edin. – luk32
@ luk32 dürüstçe, '' 've' cout' ile kesinlikle değil C –
Christophe