Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Zad3
- {
- class ZMetodą
- {
- StreamReader sr;
- StreamWriter sw;
- string[] Tab = new string[10];
- public void Wczytaj()
- {
- sr = new StreamReader("Dane.txt");
- sw = new StreamWriter("Dane2.txt");
- string słowo;
- do
- {
- słowo = sr.ReadLine();
- for (int i = 0; i < Tab.Length; i++)
- {
- if (Tab[i] == null)
- {
- Tab[i] = słowo;
- break;
- }
- else
- {
- if (słowo[0] < Tab[i][0])
- {
- for (int j = Tab.Length - 1; j > i; j--)
- {
- Tab[j] = Tab[j - 1];
- }
- Tab[i] = słowo;
- break;
- }
- else
- {
- if (słowo[0] == Tab[i][0])
- {
- if (słowo.Length < Tab[i].Length)
- {
- for (int j = Tab.Length - 1; j > i; j--)
- {
- Tab[j] = Tab[j - 1];
- }
- Tab[i] = słowo;
- break;
- }
- else
- {
- for (int j = Tab.Length - 1; j > i + 1; j--)
- {
- Tab[j] = Tab[j - 1];
- }
- Tab[i + 1] = słowo;
- break;
- }
- }
- }
- }
- }
- } while (sr.EndOfStream != true);
- int k = 0;
- do
- {
- sw.WriteLine(Tab[k]);
- k++;
- } while (k < Tab.Length && Tab[k] != null);
- sr.Close();
- sw.Close();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- ZMetodą dane = new ZMetodą();
- dane.Wczytaj();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement