sorting

  • Thread starter Thread starter MorenainHanoi
  • Start date Start date
M

MorenainHanoi

Guest
using System;

using System.Collections.Generic;

namespace sorting
{
class Program
{
static void Main(string[] args)
{
DateTime datum = DateTime.UtcNow;
Console.WriteLine(datum.ToString());

List<string[]> logBook = new List<string[]>();

Console.WriteLine("\tWelcome to the log book\n");
Console.ReadLine();

bool kör = true;
while (kör)
{

Console.WriteLine("\n\t[1]Print all entries\t");
Console.WriteLine("\t[2]Write new entry");
Console.WriteLine("\t[3]Sort all the entries");
Console.WriteLine("\t[4]Search an entry");
Console.WriteLine("\t[5]End program");
Console.Write("\tChoose: ");
int choice;
Int32.TryParse(Console.ReadLine(), out choice);

switch (choice)
{
case 1:
int max = logBook.Count;
if (max > 0)
{
for (int i = 0; i < max; i++)
{
Console.WriteLine("\t" + i + " "
+ "Title: " + logBook[0]
+ "\n\tText: " + logBook[1]);
}
}
else
Console.WriteLine("\tThe log book is empty");
Console.ReadLine();
break;
case 2:
Console.Write("\n\tWrite the title: ");
string title = Console.ReadLine();
Console.Write("\n\tWrite the text here: ");
string text = Console.ReadLine();

string[] post = new string[] { title, text };
logBook.Add(post);
break;
case 3:
max = logBook.Count;
char[] titlePost = logBook[0];//I don't understand why the "i" here isn't recognized

if (max > 2)
{
for (int i = 0; i < logBook.Count; i++)
{
var nrLeft = max - 1;
for (int j = 0; j < nrLeft; j++)
{
if (titlePost[j] > titlePost[j + 1])
{
int temp = titlePost[j];
titlePost[j] = titlePost[j + 1];
temp = titlePost[j + 1];
}
}
}
for (int i = 0; i < max; i++)
{
Console.WriteLine("\ti" + " " + logBook[0]);
}
}

else
Console.WriteLine("\tThere is only one entry in the log book" + logBook[1][0]);
Console.ReadLine();
break;
}
}
}
}
}




Hello,

Iam very newbie in programming and i have a task which shown above. I am trying to sort entries and i dont know if I did right in using char to alphabetically arrange the saved entries. I dont understand why the logBook[0] doesn't work in case 3. I also tried to save a 'date' as one of the arrays but i cant get wrap my head around it.

I really appreciate any help I could get. Thank you in advance.

-Morena

Continue reading...
 
Back
Top