110,567
社区成员
发帖
与我相关
我的任务
分享
public class MyQueue
{
public class Node
{
public Node(object data)
{
Data = data;
}
public Node NextNode = null;
public Node UpNode = null;
public object Data = null;
}
Node beginNode = null;
Node endNode = null;
public override string ToString()
{
return count.ToString();
}
int count = 0;
public int Count
{
get
{
return count;
}
set
{
count = value;
}
}
public Node Dequeue()
{
if (beginNode.NextNode == null && count>1)
{
return null;
}
Node Rerurn = beginNode;
if (Rerurn != null)
{
beginNode = beginNode.NextNode;
--count;
Rerurn.NextNode = null;
Rerurn.UpNode = null;
}
return Rerurn;
}
public void Enqueue(Node node)
{
if (beginNode == null)
{
beginNode = node;
endNode = node;
}
else
{
node.UpNode = endNode;
endNode.NextNode = node;
endNode = node;
endNode.NextNode = null;
}
++count;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace test
{
struct node
{
public int[] Data;
public int front;
public int rear;
}
public class MyQueue
{
private node temp;
private int count;
public MyQueue()
{
temp.Data = new int[160000];
temp.front = 159999;
temp.rear = 159999;
count = 0;
}
public void Enqueue(int a)
{
if (temp.front == (temp.rear+1)%160000)
{
Console.WriteLine("queue is full");
}
else
{
temp.rear = (temp.rear + 1) % 160000;
temp.Data[temp.rear] = a;
count++;
}
}
public int Dequeue()
{
if (temp.rear == temp.front)
{
Console.WriteLine("queue is empty");
return 0;
}
else
{
temp.front = (temp.front + 1) % 160000;
count--;
return temp.Data[temp.front];
}
}
public int Count
{
get
{
return count;
}
}
}
class Program
{
static void Main(string[] args)
{
test();
}
private static void test()
{
for (int a = 1000; a < 160000; a += 1000)
{
MyQueue myQueue = new MyQueue();
//以上是初始化代码
long bl2 = 0;
for (int d = 0; d < 10; d++)
{
long bl1 = DateTime.Now.Ticks;
for (int c = 0; c < 10000; c++)
{
myQueue.Enqueue(c);
}
for (int c = 0; c < 10000; c++)
{
myQueue.Dequeue();
}
bl1 = DateTime.Now.Ticks - bl1;
bl2 += bl1;
}
//以上是运行测试代码
bl2 = (bl2 / 10) / a;
Console.WriteLine(a+", "+bl2.ToString());
}
Console.Read();
}
}
}