node:یک کلاس کوچولویی از یک خونه از لیست پیوندیمونه:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cstack_ListPeyvandi
{
class Node
{
public string data;
public Node link;
public Node(string item)
{
data = item;
link = null;
}
}
}
این کلاس در مورد عملیاتیه که میخواد روی مجموعی از سلولهای یک لیست پیوندی انجام بده ، منتها متاسم الان دقیقا خاطرم نیست که داره چه کاری برامون انجام میده:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cstack_ListPeyvandi
{
class CStack
{
public Node First = null;
public string[] a = new string[100]; int i = -1;
int counter1 = 0; int counter2 = 0; int counter3 = 0; int counter4 = 0;
//------------------------------------------------
public bool IsEmptyList()
{
if (First == null)
return true;
return false;
}
//------------------------------------------------
public void Insert(string element)
{
Node NewNode = new Node(element);
if (IsEmptyList())
First = NewNode;
else
{
Node Current = First;
while (Current.link != null)
Current = Current.link;
Current.link = NewNode;
}
}
//-------------------------------------
public bool IsEmptyStack()
{
if (i == -1)
return false;
return true;
}
//-------------------------------------
public bool Check(Node p)
{
int counter = 0;
Node Curr = p;
while (Curr != null)
{
if (First.data == '('.ToString() || First.data == ')'.ToString() || First.data == '{'.ToString() || First.data == '}'.ToString())
{
a[++i] = First.data;
First = Curr.link;
counter++;
}
else if (Curr.data == '('.ToString() || Curr.data == ')'.ToString() || Curr.data == '{'.ToString() || Curr.data == '}'.ToString())
{
a[++i] = Curr.data;
counter++;
}
Curr = Curr.link;
}
if (IsEmptyStack())//چرا این دستور را نمی فهمد؟از شمارشگرها میپرد و آنها را فرا نمیخواند
{
for (int j = counter - 1; j >= 0; j--)
{
if (a[j] == "(")
{
counter1++;
a[j] = null;
}
else if (a[j] == ")")
{
counter2++;
a[j] = null;
}
else if (a[j] == "{")
{
counter3++;
a[j] = null;
}
else if (a[j] == "}")
{
counter4++;
a[j] = null;
}
}
}
if ((counter1 == counter2) && (counter3 == counter4))
return true;
return false;
}
//-----------------------------------------------
}
}
و در آخر کار فراخونی میشه در فرم اصلی:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cstack_ListPeyvandi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
CStack myCstack = new CStack();
private void btn_ClickShow_Click(object sender, EventArgs e)
{
if (myCstack.Check(myCstack.First))
MessageBox.Show("Thanks...You True Insert The List");
else
MessageBox.Show("Sorry...You False Insert The List");
علاقه مندی ها (Bookmarks)