Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Sort on frequency/bytes from .txt

$
0
0
Hi,

I want to read an file like (readthisfile.txt) read all the bytes like T=116 and the frequency(occurence of each byte) example: "test"

http://i50.tinypic.com/1pgn76.png

         private void btn_Click(object sender, EventArgs e)
        {
            
            long[] far = new long[256];
            if(ofd.ShowDialog()==DialogResult.OK)
            {
                //read file and put in bar(bytearray)
                FileStream s = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(s);               
                byte[] bar = br.ReadBytes((int)s.Length);
                foreach (var b in bar)
                {
                    //determine freqeuncy and put in far     
                    far[b]++;
                }
            }
            //put nodes in dll-list
            int index=0;
            for (byte i = 0; i < far.Length; i++)
			{
                //make node if frequency of byte <> 0
			    if(far[i]!=0)
                {
                    //create node and change head
                    cN.nar[index]=new cN(null,far[i],i,null);
                    cN.mAddNode2List(cN.nar[index]);
                }
			}
            cN.nar[512] = cN.H;
           

        }
    }


        class cN
    {
        public static cN[] nar=new cN[512];     //node array

        public static cN H=null;    //head
        private static cN W = null; //walker
        private static cN T=null;    //Tail

        private cN P;           //Previous  dll
        private long F;         //Frequency
        private byte B;         //Bytevalue
        private cN N;           //Next dll

        public cN(cN p,long f, byte b, cN n)
        {
            P=p;
            F=f;
            B=b;
            N=n;
        }

        public static void mAddNode2List(cN nX)
        {
            if (H == null)
            {
                //set first node as head
                H = nX;
            }
            else 
            {
                
                    
            }
        }
    }



With the help of an doubly linked list i want to add it in an list

But at this point i am a bit stuck, can someone give me some directions. I am not asking for the full written out code, just a little push:)

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>