Как сделать структуру. Кто поможет переделать два масива(сортировки) в структуру? Условие:
| Код | Массив записей структура которого автор, год издания, упорядочить по году издания.
|
Вот моя последняя бетта-версия ( by http://forum.codenet.ru/showpost.php...16&postcount=3 )
Работоспособная программа.
| Код | using System; using System.Collections.Generic; using System.Text;
namespace ConsoleApplication6 { class Program { class Teenager { private static Random r = new Random(); private static int GetRamdomNumber(short upperLimit) { return r.Next(upperLimit); } public static string Complain() { string[] messages = new string[6] { "Троесент!", "Ватсон!", "Фаронов!", "Шилд!", "Агуров!", "Глинський!" }; return messages[GetRamdomNumber(5)]; } }
static void Main(string[] args) { int i, x, size = 10; string y; string[] b = new string[100]; int[] d = new int[100]; Console.WriteLine("Генерация масива"); Random a = new Random(); Random c = new Random(); for (i = 0; i < size; i++) { b[i] = Teenager.Complain(); d[i] = c.Next(2007); Console.WriteLine("Название книги :" + b[i] + " Год : " + d[i]); } Console.ReadLine(); for (j = 0; j < size; j++) { for (i = 1; i < size; i++) { if (d[i - 1] > d[i]) { x = d[i - 1]; d[i - 1] = d[i]; d[i] = x;
y = b[i - 1]; b[i - 1] = b[i]; b[i] = y; } } } Console.WriteLine("Cортованый масив");
for (i = 1; i < size; i++) { Console.WriteLine(" Название книги :" + b[i] + " Год : " + d[i]); } Console.ReadLine(); } } }
|
Вот я сам сделал, но ошибки ктото может исправить?
| Код |
using System; using System.Collections.Generic; using System.Text;
namespace Struct { struct Books { public string[] autor; public int[] god; public Books(string[] a, int[] b) { autor=a; god=b; } } struct Teenager { private static Random r = new Random(); private static int GetRamdomNumber(short upperLimit) { return r.Next(upperLimit); } public static string Complain() { string[] messages = new string[6] { "Троесент!", "Ватсон!", "Фаронов!", "Шилд!", "Агуров!", "Глинський!" }; return messages[GetRamdomNumber(5)]; } } class structions { public static void Main() { string[] a = new string[6]; int[] b; int i,j,x, size=10; Random c = new Random(); for (i = 0; i < size; i++) { a = Teenager.Complain(); b = c.Next(2007); Books book = new Books(a, b); Console.WriteLine("Название книги :" + book.autor[i] + " Год : " + book.god[i]); } Console.ReadLine(); for (j = 0; j < size; j++) { for (i = 1; i < size; i++) { if (book.autor[i - 1] > book.autor[i]) { x = book.autor[i - 1]; book.autor[i - 1] = book.autor[i]; book.autor[i] = x;
} } } Console.WriteLine("Cортованый масив");
for (i = 1; i < size; i++) { Console.WriteLine(" Название книги :" + book.autor[i] + " Год : " + book.god[i]); } Console.ReadLine(); } }
}
|
|