ODD One out Quiz

Wednesday, 12 February 2014



Program to store Array Elements and perform binary search operation and sorting in C# In Windows Application form..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Array1
{


public partial class Form1 : Form
{
int size, i;
int [] table;

public Form1()
{
InitializeComponent();
}

private void button2_Click_1(object sender, EventArgs e)
{
size = Convert.ToInt32(textBox2.Text);
table = new int[size];
}


private void button1_Click(object sender, EventArgs e)
{
table[i] = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
comboBox1.Items.Add(table[i]);
listBox1.Items.Add(table[i]);
i++;
}





private void button4_Click_1(object sender, EventArgs e)
{
Array.Sort(table);
for (i = 0; i < size; i++)
{
listBox2.Items.Add(table[i]);
}
}

private void button3_Click(object sender, EventArgs e)
{
int result = Array.BinarySearch(table, Convert.ToInt32(textBox3.Text));
MessageBox.Show(result.ToString());
}



}
}

No comments:

Post a Comment