یک برنامه در مورد لیستهای تک پیوندی هست ، سوالش الان یادم نیست اما کد رو بخونین متوجه میشین برنامه در مورد چیه باز اگه جای سوالی بود بفرمایین اگه بنده نتونستم از آقایون (حسنپور، قبادی ، صالحیان )میتونین بپرسین
بااحترام
node:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sample.Net
{
class Node
{
public int data;
public Node link;
//---------------------------
public Node(int element)
{
data = element;
link = null;
}
//---------------------------
}
}
کلاس لیست پیوندی:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Sample.Net
{
class LinkedList
{
public Node first = null;
//---------------------------------------------------------------
public bool Empty()
{
if (first == null)
return true;
return false;
}
//--------------------------------------------------------------------
public void InsertTheFirst(int item)
{
Node n = new Node(item);
if (Empty())
first = n;
else
{
n.link = first;
first = n;
}
}
//----------------------------------------------------------------------
public void InsertTheEnd(int item)
{
Node n = new Node(item);
if (Empty())
first = n;
else
{
Node p;
p = first;
while (p.link != null)
p = p.link;
p.link = n;
}
}
//-------------------------------------------------------------------------
public int Show(int number)
{
Node n = new Node(number);
Node temp;
temp = first;
if (Empty())
return 0;
for (int i = 1; i <number; i++)
temp = temp.link;
return temp.data;
}
//------------------------------------------
public void SortListSoodi(Node p)
{
Node temp1, temp2;
int temp3;
temp1 = p;
do
{
temp2 = temp1.link;
if (temp2 == null) break;
do
{
if (temp1.data > temp2.data)
{
temp3 = temp1.data;
temp1.data = temp2.data;
temp2.data = temp3;
}
temp2 = temp2.link;
} while (temp2 != null);
temp1 = temp1.link;
} while (temp1 != null);
}
//----------------------------------------------------
public void SortListNozooli(Node p)
{
Node temp1, temp2;
int temp3;
temp1 = p;
do
{
temp2 = temp1.link;
if (temp2 == null) break;
do
{
if (temp1.data < temp2.data)
{
temp3 = temp1.data;
temp1.data = temp2.data;
temp2.data = temp3;
}
temp2 = temp2.link;
} while (temp2 != null);
temp1 = temp1.link;
} while (temp1 != null);
}
//------------------------------------------------------
public void DeleteMaxNodeFromSoodi()
{
Node temp1 = first;
while (temp1.link.link != null)
temp1 = temp1.link;
temp1.link = null;
}
//--------------------------------------------------------
public void DeleteMinNodeFromSoodi()
{
Node temp2 = first;
first = temp2.link;
temp2 = null;
}
//-------------------------------------
public void DeleteMaxNodeFromNozooli()
{
Node temp2 = first;
first = temp2.link;
temp2 = null;
}
//------------------------------------
public void DeleteMinNodeFromNozooli()
{
Node temp1 = first;
while (temp1.link.link != null)
temp1 = temp1.link;
temp1.link = null;
}
//--------------------------------
}
}
فراخونی در فرم اصلی:
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 Sample.Net
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//-------------------------------------------------
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 Calculate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
علاقه مندی ها (Bookmarks)