请给个源程序。这种数据结构的C语言很多。如何改成JAVA的

解决方案 »

  1.   

    我想,   
      1。符号表中的符号应按字典顺序预先排好;   
      2。在词法分析器,每遇到一个符号,利用对半查找法以logN的速度来定位   。
      

  2.   

    我曾经在一个数据结构java版的书中
    看到过 你去找找吧
      

  3.   

    曾经在一本 Java版的数据结构 中看到过
    你去找找吧 网上有的
      

  4.   

    用来压缩的
    自己写吧,不难,JAVA数据结构这本书上有介绍
      

  5.   

    JAVA数据结构源程序上有这一句编译不过
    public class Huffman {    
    public (LinkedHashMap<Character,Integer> map){    
          charTable = map;    
      charset = map.keySet();    
      creatHuffmanTree();    
      creatHuffmanCode();    
          
          
     }
    //public (LinkedHashMap<Character,Integer> map)
    C:\Documents and Settings\lenovo\j2mewtk\2.5.2\apps\FPDemo\src\calculator\Huffman.java:200: -source 1.3 中不支持泛型
    (请尝试使用 -source 1.5 以启用泛型)
    要怎样改    
      

  6.   

    //这段C基本通过,帮改成java;
    #include<stdio.h>
     #include<stdlib.h>
    #define MaxValue 10000
     #define MaxBit 10
     #define MaxN 100
    typedef struct 
    {  
    int weight;
    int flag;
    int parent;
    int leftChild;
    int rightChild;
    }HaffNode;
    typedef struct
    {
    int  bit[MaxN];
    int start;
    int weight;
    }Code;void Haffman(int weight[], int n ,HaffNode haffTree[])
    {
    int i,j,m1,m2,x1,x2;
    for(i=0;i<2*n-1;i++)
    {
    if(i<n)haffTree[i].weight=weight[i];
    else haffTree[i].weight=0;
    haffTree[i].parent=-1;
    haffTree[i].flag=0;haffTree[i].leftChild=-1;
    haffTree[i].rightChild=-1;
    } for(i=0;i<n-1;i++)

    m1=m2=MaxValue;
    x1=x2=0;
    for(j=0;j<n+1;j++)
    {
    if(haffTree[j].weight<m1&&haffTree[j].flag==0)
    {
    m2=m1;
    x2=x1;
    m1=haffTree[j].weight;
    x1=j;
    }
    else if(haffTree[j].weight<m2&&haffTree[j].flag==0)
    {
    m2=haffTree[j].weight;
    x2=j;
    }
    }
    haffTree[x1].parent=n+i;
            haffTree[x2].parent=n+i;
            haffTree[x1].flag=1;
    haffTree[x2].flag=1;
    haffTree[n+1].weight=haffTree[x1].weight+haffTree[x2].weight;
    haffTree[n+i].leftChild=x1;
    haffTree[n+i].leftChild=x2;
    }
    }  void HaffmanCode(HaffNode haffTree[],int n,Code haffCode[])
     {
     Code *cd=(Code *)malloc(sizeof(Code));
     int i,j,child,parent;
     for(i=0;i<n-1;i++)
     {
     cd->start=n-1;
     cd->weight=haffTree[i].weight;
     child=i;
     parent=haffTree[child].parent;  while(parent !=-1)
     {
     if(haffTree[parent].leftChild==child)
      cd->bit[cd->start]=1;
     cd->start--;
     child=parent;
     parent=haffTree[child].parent;
     }  for(j=cd->start+1;j<n;j++)
       haffCode[i].bit[j]=cd->bit[j];
    haffCode[i].start=cd->start+1; 
            haffCode[i].weight=cd->weight;
     }
     }
     void main(void)
     {
     int i,j,n=4;
     int weight[]={1,3,5,7};
     HaffNode *myHaffTree=(HaffNode *)malloc(sizeof(HaffNode)*(2*n+1));
     Code *myHaffCode=(Code *)malloc(sizeof(Code)*n);
     if(n>MaxN)
     {
     printf("out\n");
     exit(0);
     }
     Haffman(weight,n,myHaffTree);
     HaffmanCode(myHaffTree,n,myHaffCode);
     for(i=0;i<n;i++)
     {
     printf("Weight=%d",myHaffCode[i].weight);
     for(j=myHaffCode[i].start;j<n;j++)
     printf("%d",myHaffCode[i].bit[j]);
     printf("\n");
     } }