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 LinkedList
{
public partial class Form1 : Form
{
int n = 100;
int[] a;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
a = new int[n];
Random x = new Random();
textBox1.Text = "";
for(int i=0;i<n;i++)
{
a[i] = x.Next(100) + 1;
textBox1.Text = textBox1.Text + "[" +i.ToString() + "]"+a[i].ToString() + " , ";
}
}
private int sequentialsearch(int k)
{
int i=0;
while(i<n && a[i] !=k)
{
i++;
}
if (i < n)
return i;
else
return -1;
}
private void button2_Click(object sender, EventArgs e)
{
int k = Convert.ToInt32(textBox2.Text);
textBox3.Text = sequentialsearch(k).ToString();
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น