Created
November 26, 2015 09:11
-
-
Save Sprite105/f6c50d8fafd3173c9413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication5 | |
{ | |
class MyQueue { | |
private QueueMember[] myQueue; | |
private int current = 0; | |
public MyQueue(int num) { | |
this.myQueue = new QueueMember[num]; | |
} | |
private class QueueMember { | |
public Object data; | |
public int parent; | |
public QueueMember(Object data, int parent) { | |
this.data = data; | |
this.parent = parent; | |
} | |
} | |
public void Add(Object data) { | |
if (current <= myQueue.Length-1) { | |
myQueue[current] = new QueueMember(data, current - 1); | |
current++; | |
} | |
} | |
public Object Remove() { | |
Object temp = myQueue[0].data; | |
for (int i = 1; i < current; i++) { | |
myQueue[i - 1] = myQueue[i]; | |
} | |
myQueue[current-1] = null; | |
current--; | |
myQueue[current].parent--; | |
return temp; | |
} | |
public override string ToString() | |
{ | |
String s = "{ "; | |
for (int i = 0; i < current; i++) { | |
s = s + myQueue[i].data.ToString() + ", "; | |
} | |
s = s.Substring(0, s.Length - 2) + " }"; | |
return s; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment