hi
i have a project in my university
we should programming knapsack algorithm
user should enter capacity and items count of knapsack & weight & value .it must be with GUI. i program this project with c#.but i have some problems with design for this code GUI.
someone please help me..
below its my c sharp code .i want GUI for this but i cant..
sorry for my english
What I have tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace KnapsackAlgo
{
class KnapsackAlgorithm
{
public static int KnapSack(int capacity, int[] weight, int[] value, int itemsCount)
{
int[,] K = new int[itemsCount + 1, capacity + 1];
for (int i = 0; i <= itemsCount; ++i)
{
for (int w = 0; w <= capacity; ++w)
{
if (i == 0 || w == 0)
K[i, w] = 0;
else if (weight[i - 1] <= w)
K[i, w] = Math.Max(value[i - 1] + K[i - 1, w - weight[i - 1]], K[i - 1, w]);
else
K[i, w] = K[i - 1, w];
}
}
return K[itemsCount, capacity];
}
static void Main(string[] args)
{
Console.WriteLine("enter itemscount:");
int itemsCount = int.Parse(Console.ReadLine());
Console.WriteLine("enter capacity of knapsack:");
int capacity = int.Parse(Console.ReadLine());
int[] value = new int[itemsCount];
int[] weight = new int[itemsCount];
Console.WriteLine("enter values of items:");
for (int i = 0;i < itemsCount;i++)
{
int x = int.Parse(Console.ReadLine());
value[i] = x;
}
Console.WriteLine("enter weights of items:");
for (int j=0; j < itemsCount; j++)
{
int y = int.Parse(Console.ReadLine());
weight[j] = y;
}
int result = KnapSack(capacity, weight, value, itemsCount);
Console.WriteLine(result);
}
}
}