Exemple #1
0
        public static void Test_File(int seed, int n)
        {
            string filename;


            filename = @"mydataarray.dat";
            MyFileArray myFileArray = new MyFileArray(filename, n, seed);

            using (myFileArray.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n FILE ARRAY \n");
                myFileArray.Print(n);
                insertion(myFileArray);
                myFileArray.Print(n);
            }


            filename = @"mydatalist.dat";
            MyFileList myfilelist = new MyFileList(filename, n, seed);

            using (myfilelist.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n file List \n");
                myfilelist.Print(n);
                insertsortlistForFile(myfilelist);
                myfilelist.Print(n);
            }
        }
Exemple #2
0
        public static void insertsortlistForFile(MyFileList items)
        {
            double prevdata, currentdata;

            for (int i = 1; i < items.Length; i++)
            {
                currentdata = items.Head();

                for (int k = 0; k < i; k++)
                {
                    prevdata    = currentdata;
                    currentdata = items.Next();
                }
                double item = currentdata; // isrenkamas nuo antro iki galinio kiekvienas elementas

                int ins = 0;
                for (int j = i - 1; j >= 0 && ins != 1;)
                {
                    currentdata = items.Head();
                    for (int k = 0; k < j; k++)
                    {
                        prevdata    = currentdata;
                        currentdata = items.Next();
                    }

                    if (item < currentdata) // tikrinama su esanciais pirmesniais elementais pradedant nuo artimesnio
                    {
                        // sukeitinejamas item elementas su esanciais pirmesniai elementais tol jie bus uz ji didesni
                        prevdata    = currentdata;
                        currentdata = items.Next();
                        items.Swap(currentdata, prevdata);
                        j--;
                    }
                    else
                    {
                        ins = 1;  // jei neatliktas pakeitimas sekanciu artimesniu nariu iseinama is ciklo
                    }
                }
            }
        }