用类实现啊:public class Link { int number; Link next; public Link(int val) { this.number = val; next = null; }
//增加链 public void Add(int val);
//删除链 public void Remove(int val); }
用ArrayList 面的代码示例演示如何创建并初始化 ArrayList 以及如何打印出其值 using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!"); // Displays the properties and values of the ArrayList. Console.WriteLine( "myAL" ); Console.WriteLine( " Count: {0}", myAL.Count ); Console.WriteLine( " Capacity: {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { foreach ( Object obj in myList ) Console.Write( " {0}", obj ); Console.WriteLine(); }} /* This code produces output similar to the following:myAL Count: 3 Capacity: f Values: Hello World !*/
{
int number;
Link next; public Link(int val)
{
this.number = val;
next = null;
}
//增加链
public void Add(int val);
//删除链
public void Remove(int val);
}
面的代码示例演示如何创建并初始化 ArrayList 以及如何打印出其值
using System;
using System.Collections;
public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!"); // Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( " Count: {0}", myAL.Count );
Console.WriteLine( " Capacity: {0}", myAL.Capacity );
Console.Write( " Values:" );
PrintValues( myAL );
} public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.Write( " {0}", obj );
Console.WriteLine();
}}
/*
This code produces output similar to the following:myAL
Count: 3
Capacity: f
Values: Hello World !*/