Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Visual-Studio Forms
write a program that sorts a content of txt file using an external merge sort????????
we r done with the coding of browse a file and shown in text file..
we dont knw how to apply the merge sort on txt file and then again sort it in array.
In Form we used brows button,append button,2 textview,merge button,write button and sort in array button,,,,,,,,,
plz anyone help us
here our coding
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
namespace Splitfiles
{
 
    public partial class Form1 : Form
    {
        public FileStream fs;
        System.IO.StreamWriter writer;
 
        string file_write;
 
        public Form1()
        {
            InitializeComponent();
        }
 

        //List<string> Packets = new List<string>();

        //Merge file is stored in drive
        //string SaveFileFolder = @"c:\";

        private void brows_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog1.ShowDialog();
                txtBrowsFile.Text = openFileDialog1.FileName;
 
                fs = new FileStream(txtBrowsFile.Text, FileMode.Open, FileAccess.Read);
                string name = Path.GetFileName(txtBrowsFile.Text);
                //int FileLength = (int)fs.Length / 1024;

            }
            catch (Exception ex)
            {
                lblSendingResult.Text = "EXCEPTION:" + ex;
            }
        }
 

 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //string fpath="E:\\one.txt";
            string name = Path.GetFileName(txtBrowsFile.Text);
            StreamReader dr = new StreamReader(Path.GetFileName(txtBrowsFile.Text));
 

 
            while (dr.Peek() != -1)
            {
                string contents = dr.ReadToEnd();
                /*string[] mer = new string[contents.Length];
                int len = contents.Length;
                int i = 0;
                for (i = 0; i < len; i++)
                {
                    mer[i] = (contents);*/
 

                textBox1.Text = contents;
 

            }
 
            txtBrowsFile.Clear();
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //StreamWriter dw = new StreamWriter(Path.GetFileName(txtBrowsFile.Text));

 
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            string name = Path.GetFileName(txtBrowsFile.Text);
            StreamReader dr = new StreamReader(Path.GetFileName(txtBrowsFile.Text));
            string content;
 
            content = dr.ReadToEnd().ToString();
 
            textBox2.Text = textBox1.Text + (content);
            textBox1.Clear();
 

        }
 
        private void button4_Click(object sender, EventArgs e)
        {
 

            //string name = Path.GetFileName(txtBrowsFile.Text);
            //StreamWriter dw = new StreamWriter (Path.GetFileName(txtBrowsFile.Text),true);
            //StreamWriterfile_write = "Path.GetFileName(txtBrowsFile.Text)";
            //writer = new System.IO.StreamWriter(file_write, true);
            //dw.Write(textBox2.Text);
            //dw.Close();
            file_write = "C:\\Users\\asadali\\Documents\\file.txt";
            writer = new System.IO.StreamWriter(file_write);
            writer.Write(textBox2.Text);
            
            writer.Close();
            MessageBox.Show("wrote File");
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            string name = "C:\\Users\\asadali\\Documents\\file.txt";
            StreamReader dr = new StreamReader(name);
            while (dr.Peek() != -1)
            {
                string contents = dr.ReadToEnd();
                string[] mer = new string[contents.Length];
                int len = contents.Length;
                int i = 0;
                for (i = 0; i < len; i++)
                {
                    mer[i] = (contents);
                    textBox1.Text = contents;
 
                }
                /*   string[] arr = textBox2.Lines;
                   int i;
                   for (i = 0; i < arr.Length; i++)
                   {
 
                       textBox2.Text = arr[i];
 
                       i++;
                       arr[i] = textBox1.Text;
                   }*/
 
            }
            //string [] contentss = textBox2.Lines.ToArray();

            // for( int i=0;i<contentss.length;i++)>
            //{

            //string[] lines = File.ReadAllLines("C:\\Users\\asidali\\Documents\\file.txt");

            //string[] a = new string[lines.Length];
            //int i;
            //for ( i = 0; i < lines.Length; i++)
            //{
            //  lines[i] = a[i];
            //a[i] = textBox1.Text;
            //}
            //.textBox1a[i] = textBox1.Text;
        }
    }
}
            /*string name = Path.GetFileName(txtBrowsFile.Text);
            StreamReader dr = new StreamReader(Path.GetFileName(txtBrowsFile.Text));
 
            while (dr.Peek() != -1)
            {
                string contents = dr.ReadToEnd();
                string[] mer = new string[contents.Length];
                int len = contents.Length;
                int i = 0;
                for (i = 0; i < len; i++)
                {
                    mer[i] = (contents);
 

                    textBox1.Text = contents;
 
                }
 
                //string[] lines = this.textBox1.Text.Split('\n');
                //MessageBox.Show(lines.Length.ToString());
 
        }
    }
            /*private string[] Mergeso                                                                                                                                            rt(string[] mer)
 {
     if (mer.Length <= 1)
     {
         return mer;
     }
 
     int firstPart = mer.Length / 2;
     string[] strings1 = new string[firstPart];
     string[] strings2 = new string[mer.Length - firstPart];
 
     string[] sorted = new string[mer.Length];
 
     // Split the array into two;
     for (int i = 0; i < firstPart; i++)
     {
                                                                                                                                                                                                                                                                                                                                                                                                                  strings1[i] = mer[i];
     }
 
     for (int i = firstPart; i < mer.Length; i++)
     {
         strings2[i - firstPart] = mer[i];
     }
 
     strings1 = Mergesort(strings1);
     strings2 = Mergesort(strings2);
 
     int j = 0;
     int k = 0;
 
     for (int i = 0; i < sorted.Length; i++)
     {
         if (j == strings1.Length)
         {
             sorted[i] = strings2[k];
             k++;
         }
         else if (k == strings2.Length)
         {
             sorted[i] = strings1[j];
             j++;
         }
         else if (stringcompare(strings1[j], strings2[k]))
         {
             sorted[i] = strings1[j];
             j++;
         }
         else
         {
             sorted[i] = strings2[k];
             k++;
         }
     }
 
     return sorted;
 }
        
}*/</string></string>
Posted 1-Jun-13 8:54am
Edited 1-Jun-13 12:50pm
v3
Comments
Christian Graus at 1-Jun-13 17:54pm
   
You're going to fail your class. You need to able to do this stuff yourself, that's what a class is for. Once you know how to code, you can use these forums to ask questions about specific areas you get stuck on things not well documented on the web. But, we're not going to do your assignment for you, because we want you to be able to program, if you ever manage to graduate and, heaven forbid, end up in the desk next to us
TnTinMn at 1-Jun-13 20:59pm
   
I wish you would have posted this comment as a solution so that I could have given you a +5. :)
Christian Graus at 1-Jun-13 21:47pm
   
*grin* well, I'd like to, to get this out of 'unanswered questions', but it's not really an answer, so it seemed better to not mess with how the site indexes such things.
TnTinMn at 1-Jun-13 23:11pm
   
Understood, and for what it is worth have another gratuitous +5 for your integrity. It frustrates me seeing so many supposed solutions that are nothing more than comments from those who should know and act better.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 195
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 1 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100