111,128
社区成员
发帖
与我相关
我的任务
分享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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LinkedList<A, int> a = new LinkedList<A, int>(new A(0),2);
A a1 = new A(1);
A a2 = new A(2);
A a3 = new A(3);
a.AddHead(a1, 11);
a.AddHead(a2, 22);
a.AddHead(a3, 33);
A a4 = new A(4);
int i = a.Find(a2);
MessageBox.Show(i.ToString());
}
}
class Node<K, T>
{
public K Key;
public T Item;
public Node<K, T> NextNode;
public Node()
{
Key = default(K);
Item = default(T);
NextNode = null;
}
public Node(K key, T item, Node<K, T> nextNode)
{
Key = key;
Item = item;
NextNode = nextNode;
}
}
public class LinkedList<K, T>
{
Node<K, T> m_Head;
public LinkedList(K key,T item)
{
m_Head = new Node<K, T>(key,item,null);
}
public void AddHead(K key, T item)
{
Node<K, T> newNode = new Node<K, T>(key, item, m_Head.NextNode);
m_Head.NextNode = newNode;
}
public T Find(K key)
{
Node<K, T> current = m_Head;
while (current.NextNode != null)
{
if (((IComparable)(current.Key)).CompareTo(key) == 0)
break;
else
current = current.NextNode;
}
return current.Item;
}
}
public class A : IComparable
{
private int myprop;
public A(int i)
{
myprop = i;
}
public int CompareTo(object obj)
{
if ((A)this == ((A)obj))
{
return 0;
}
else return -1;
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LinkedList<A, int> a = new LinkedList<A, int>(new A(0),2);
A a1 = new A(1);
A a2 = new A(2);
A a3 = new A(3);
a.AddHead(a1, 11);
a.AddHead(a2, 22);
a.AddHead(a3, 33);
A a4 = new A(4);
int i = a.Find(a2);
MessageBox.Show(i.ToString());
}
}
class Node<K, T>
{
public K Key;
public T Item;
public Node<K, T> NextNode;
public Node()
{
Key = default(K);
Item = default(T);
NextNode = null;
}
public Node(K key, T item, Node<K, T> nextNode)
{
Key = key;
Item = item;
NextNode = nextNode;
}
}
public class LinkedList<K, T>
{
Node<K, T> m_Head;
public LinkedList(K key,T item)
{
m_Head = new Node<K, T>(key,item,null);
}
public void AddHead(K key, T item)
{
Node<K, T> newNode = new Node<K, T>(key, item, m_Head.NextNode);
m_Head.NextNode = newNode;
}
public T Find(K key)
{
Node<K, T> current = m_Head;
while (current.NextNode != null)
{
if (((IComparable)(current.Key)).CompareTo(key) == 0)
break;
else
current = current.NextNode;
}
return current.Item;
}
}
public class A : IComparable
{
private int myprop;
public A(int i)
{
myprop = i;
}
public int CompareTo(object obj)
{
if ((A)this == ((A)obj))
{
return 0;
}
else return -1;
}
}
}