پیدا کردن بزرگترین و کوچکترین مقدار با لیستهای پیوندی
کلاس:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace STUDENT
{
public class Linklist
{
public node first = new node();
public node current = new node();
public node max = new node();
public node min = new node();
// public string print;
public string more;
public string less;
public node b = new node();
public bool a;
public Linklist()
{
first = null;
}
public void add(string name,int id,int average)
{
node n = new node(name,id,average);
if (first == null)
{
a = true;
first = n;
current = first;
}
else
{
a = false;
current = first;
while (current.Next != null)
current = current.Next;
current.Next = n;
}
}
public node FindMax()
{
current = first;
max = current;
while(current.Next!=null)
{
if (current.Next.Average > current.Average)
{
max = current.Next;
current = current.Next;
}
else
current = current.Next;
}
return max;
}
public node FindMin()
{
current = first;
min = current;
while (current.Next != null)
{
if (current.Next.Average < current.Average)
{
min = current.Next;
current = current.Next;
}
else
{
current = current.Next;
}
}
return min;
}
public string FindMore(int avg)
{
more = "";
current = first;
while (current!= null)
{
if (current.Average <= avg)
current = current.Next;
else
{
more = more + current.Name+" : "+current.Id+" / "+current.Average+"\n";
current = current.Next;
}
}
return more;
}
public String FindLess(int avg)
{
less = "";
current = first;
while (current != null)
{
if (current.Average >= avg)
current = current.Next;
else
{
less = less + current.Name + " : " + current.Id + " / " + current.Average + "\n";
current = current.Next;
}
}
return less;
}
}
}
فراخونی:
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;
using System.Media;
namespace STUDENT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (txtName.Text != "" && txtId.Text != "")
{
string a = txtName.Text;
int b = Convert.ToInt32(txtId.Text);
int c = Convert.ToInt32(txtAv.Text);
l.add(a, b, c);
علاقه مندی ها (Bookmarks)