Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp9
- {
- class Program
- {
- static void Wczytaj(string sciezka)
- {
- try
- {
- using (StreamReader streamReader = new StreamReader(sciezka))
- {
- string linia = null;
- double x;
- int licznik = 0;
- while ((linia = streamReader.ReadLine()) != null)
- {
- licznik++;
- try
- {
- x = Convert.ToDouble(linia);
- liczba.Add(x);
- }
- catch(FormatException er)
- {
- Console.WriteLine("Blad w {0} linii", licznik);
- }
- catch(Exception er)
- {
- Console.WriteLine(er.ToString());
- }
- }
- }
- }
- catch (IOException error)
- {
- Console.WriteLine(error.ToString());
- }
- catch (Exception error)
- {
- Console.WriteLine(error.ToString());
- }
- }
- static void Zapisz(string sciezka)
- {
- try
- {
- using (StreamWriter sw = new StreamWriter(sciezka))
- {
- for (int i = 0; i < 100; i++)
- {
- if(i % 20 == 0)
- sw.WriteLine("ERROR");
- else
- sw.WriteLine(rand.Next(200));
- }
- }
- }
- catch (IOException error)
- {
- Console.WriteLine(error.ToString());
- }
- catch (Exception error)
- {
- Console.WriteLine(error.ToString());
- }
- finally
- {
- Console.WriteLine("Zapisano");
- }
- }
- static void Sortuj(List<double> lista)
- {
- double x;
- int j;
- for (int i = 1; i < lista.Count(); i++)
- {
- x = lista[i];
- j = i - 1;
- while(j >= 0 && lista[j] > x)
- {
- lista[j + 1] = lista[j];
- j--;
- }
- lista[j + 1] = x;
- }
- }
- static void Wyswietl(List<double> lista)
- {
- for (int i = 0; i < lista.Count(); i++)
- {
- Console.WriteLine(lista[i]);
- }
- }
- static Random rand = new Random();
- static List<double> liczba = new List<double>();
- static void Main(string[] args)
- {
- string sciezka = @"..\..\Dane\Zadanie3.csv";
- if (!File.Exists(sciezka))
- File.Create(sciezka);
- Zapisz(sciezka);
- Wczytaj(sciezka);
- Sortuj(liczba);
- Wyswietl(liczba);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement