Dictionary.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Dictionary<T1,T2>
{
T1[] key;
T2[] value;
int pos;
public Dictionary(int size)
{
key = new T1[size];
value = new T2[size];
pos = 0;
}
public void Add(T1 ke,T2 val)
{
key[pos] = ke;
value[pos] = val;
pos++;
}
public string Remove()
{
string re = key[pos-1].ToString();
re += " ";
re += value[pos-1].ToString();
pos--;
return re;
}
public void Display()
{
for (int i = 0; i < pos; i++)
{ Console.WriteLine("{0} {1}",key[i],value[i]); }
}
}
}
List.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class List<T>
{
private T[] l;
int pos;
public List(int size)
{
l = new T[size];
pos = 0;
}
public void Add(T val)
{
l[pos] = val;
pos++;
}
public T Remove()
{
T r = l[pos-1];
pos--;
return r;
}
public void Display()
{
for (int i = 0; i < pos; i++)
{ Console.WriteLine(l[i]); }
}
}
}
Queue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Quene<T>
{
private T[] q;
int pos;
public Quene(int size)
{
q = new T[size];
pos = 0;
}
public void Enqueue(T val)
{
q[pos] = val;
pos++;
}
public T Dequeue()
{
T r = q[0];
for (int i = 0; i < pos - 1; ++i)
q[i] = q[i + 1];
pos--;
return r;
}
public void Display()
{
for(int i = 0;i < pos; i++)
{Console.WriteLine(q[i]);}
}
}
}
Stack.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Stack<T>
{
private T[] s;
int pos;
public Stack(int size)
{
s = new T[size];
pos = 0;
}
public void Push(T val)
{
s[pos] = val;
pos++;
}
public T Pop()
{
pos--;
return s[pos];
}
public void Display()
{
for (int i = pos - 1; i >= 0; --i)
{Console.WriteLine(s[i]);}
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
List<int> l = new List<int>(2);
l.Add(1);
l.Add(2);
Console.WriteLine("链表里面的元素:");
l.Display();
Console.WriteLine("删除的元素:");
Console.WriteLine(l.Remove());
Console.WriteLine("链表里面的元素:");
l.Display();
Quene<int> q = new Quene<int>(2);
q.Enqueue(1);
q.Enqueue(2);
Console.WriteLine("\n\n队列里面的元素:");
q.Display();
Console.WriteLine("删除元素:");
Console.WriteLine(q.Dequeue());
Console.WriteLine(q.Dequeue());
Console.WriteLine("队列里面的元素:");
q.Display();
Stack<int> s = new Stack<int>(2);
s.Push(1);
s.Push(2);
Console.WriteLine("\n\n栈里面的元素:");
s.Display();
Console.WriteLine("出栈元素:");
Console.WriteLine(s.Pop());
Console.WriteLine("栈里面的元素:");
s.Display();
Dictionary<int,string> d = new Dictionary<int,string>(2);
d.Add(1,"one");
d.Add(2,"two");
Console.WriteLine("\n\n字典里面的元素:");
d.Display();
Console.WriteLine("删除元素:");
Console.WriteLine(d.Remove());
Console.WriteLine("字典里面的元素:");
d.Display();
}
}
}