using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList HT = new ArrayList();
Console.WriteLine("Enter Numbers :");
for (int i = 0; i < 5; i++)
{
ABC obj = new ABC();
obj.str = Console.ReadLine();
obj.dbl = Convert.ToDouble(obj.str);
HT.Add(obj);
}
Console.WriteLine("Enter A to J:");
for (int i = 5; i < 10; i++)
{
ABC obj = new ABC();
obj.str = Console.ReadLine();
obj.dbl = returnValue(obj.str);
HT.Add(obj);
}
ArrayList arrObj = new ArrayList();
for (int pass = 1; pass <= HT.Count - 2; pass++)
{
for (int i = 0; i <= HT.Count - 2; i++)
{
ABC obj1 = (ABC)HT[i];
ABC obj2 = (ABC)HT[i + 1];
if (obj1.dbl > obj2.dbl)
{
ABC temp = (ABC)HT[i + 1];
HT[i + 1] = HT[i];
HT[i] = temp;
}
}
}
foreach (ABC obj1 in HT)
{
Console.WriteLine(obj1.str.ToString());
}
Console.ReadLine();
}
private static double returnValue(string str)
{
switch (str.ToUpper())
{
case "A":
return 0;
case "B":
return 1;
case "C":
return returnValue("A") + returnValue("B");
case "D":
return returnValue("B") + returnValue("C");
case "E":
return returnValue("C") + returnValue("D");
case "F":
return returnValue("D") + returnValue("E");
case "G":
return returnValue("E") + returnValue("F");
case "H":
return returnValue("F") + returnValue("G");
case "I":
return returnValue("G") + returnValue("H");
case "J":
return returnValue("H") + returnValue("I");
default: return 0;
}
}
}
public class ABC
{
string _str = string.Empty;
public string str { get { return _str; } set { _str = value; } }
double _dbl = 0.0;
public double dbl { get { return _dbl; } set { _dbl = value; } }
}
}
Validation is still missing.(i think u can do it)
PLEASE MARK AS ANSWER IF IT HELPS YOU.
Sandeepkasar, if this helps please login to Mark As Answer. | Alert Moderator