运行没有运行结果
不知道哪里错,当时改代码改着电脑黑屏有个鼠标箭头,但是怎么按键都不好使,电脑就运行着dev一个程序而已,过了一会后重启卡了一会又好了,不过再乱动了。。。void bottonToUp(HuffmanTree &HfTree,int size)
{
int temp;
int i;
for( i=1;i<=size;i++)
{
Node node=HfTree;
while(node.parent!=0)
{
temp=HfTree.parent;
if(HfTree.left==i)
s.push('0');
else if(HfTree.right==i)
s.push('1');
node=HfTree;
}
char c;
int j=0;
while(!s.empty())
{
c=s.top();
j++;
s.pop();
}
strcpy(HfTree.code,c);
// cout<<c;
//HfTree.code=atoi(c);
for(int k=0;k<26;k++)
cout<<HfTree.code<<endl;
}
} #include <iostream>
#include <fstream>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
typedef char Elemtype;
typedefstruct Node{
charcode;
Elemtype data;
double weight;
int left ,right,parent;
}Node,*HuffmanTree;
void createHuffmanTree(HuffmanTree &HfTree ,int size);
void bottonToUp(HuffmanTree &HfTree,int size);
int number;
stack<int> s;
void frame()
{
cout<<"1-----创建26个字母表使用频率的哈夫曼树"<<endl;
}
int main(void)
{
frame();
int size=26;
cout<<"请输入节点数"<<endl;
cin>>size;
if(size<=1)
{
cout<<"节点数目不足于构建哈夫曼树"<<endl;
return 0;
}
number=2*size-1;
HuffmanTree HfTree=new Node;
createHuffmanTree(HfTree,size);
// for(int i=1;i<=number;i++)
//cout<<HfTree.weight;
bottonToUp(HfTree,size);
}
int a={0}; void SelectMin(HuffmanTree &HfTree,int &min1,int &min2)
{
double count1,count2 ;
int j=1;
int cal=1;
for(cal;cal<number;cal++)
{
if(a==0)
{
count1=HfTree.weight;
break;
}
else
++cal;
}
for( j;j<number;++j)
{
if(a==1)
continue;
else if((HfTree.weight!=0)&&(count1>=HfTree.weight))
{
count1=HfTree.weight;
min1=j;
}
}
a=1;
j=1;
cal=1;
for(cal;cal<number;cal++)
{
if(a==0)
{
count2=HfTree.weight;
break;
}
}
for(j;j<number;j++)
{
if(j==min1|a==1)
continue;
else if((HfTree.weight!=0)&&(count2>=HfTree.weight))
{
count2=HfTree.weight;
min2=j;
}
}
a=1;
} void createHuffmanTree( HuffmanTree &HfTree ,int size)
{
cout<<number<<endl;
Elemtype e;
int i, min1 ,min2;
for( i=1;i<=number;i++)
{
HfTree.parent=0;
HfTree.left=0;
HfTree.right=0;
HfTree.weight=0;
}
ifstreaminfile("LetterMap.txt");
i=1;
while(infile>>HfTree.data)
{
infile>>HfTree.weight;
++i;
}
for(i;i<=number;i++)
{
SelectMin(HfTree ,min1,min2);
HfTree.parent=i;
HfTree.parent=i;
HfTree.left=min1;
HfTree.right=min2;
HfTree.weight=HfTree.weight+HfTree.weight;
}
} stack那里是char的 除了bottonToUp其他地方都没问题 没事了
页:
[1]