جستجوی خطی
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace linersearch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int i = 0;
public int[] a = new int[100];
private void button2_Click(object sender, EventArgs e)
{
a[i] = Int32.Parse(textBox2.Text);
i++;
listBox1.Items.Add(textBox2.Text);
}
public int lsearch(int x, int[] ls,int l)
{
if (l > ls.Length)
return (-1);
else if (x == ls[l])
return (l);
else
return(lsearch(x,ls,l+1));
}
private void button1_Click(object sender, EventArgs e)
{
int low = 0;
textBox3.Text = (lsearch(Int32.Parse(textBox2.Text), a, low)).ToString();
}
}
}