SOURCE CODE
using System; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace linklist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
LinkedList<string> LinkedList = new LinkedList<string>();
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
textBox1.Text = "";
foreach (var item in LinkedList)
{
listBox1.Items.Add(item);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
string add = textBox1.Text;
if (FirstRb.Checked)
{
string find = listBox1.SelectedItem.ToString();
LinkedListNode<string> node = LinkedList.Find(find);
LinkedList.AddAfter(node, add);
}
else if(secRb.Checked)
{
string find = listBox1.SelectedItem.ToString();
LinkedListNode<string> node = LinkedList.Find(find);
LinkedList.AddBefore(node, add);
}
else
LinkedList.AddLast(textBox1.Text);
statusLabl.Text = "Status : " + textBox1.Text + " Added to List";
}
private void button3_Click(object sender, EventArgs e)
{
try
{
string RemoveItem = listBox1.SelectedItem.ToString();
// LinkedList.RemoveLast();
LinkedList.Remove(RemoveItem);
statusLabl.Text = "Status : " + RemoveItem + " Removed From List";
}
catch (Exception ) { MessageBox.Show("Please! Select A Value in List","Stop"); }
}
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
}
}
No comments:
Post a Comment