67 lines
1.2 KiB
C#
67 lines
1.2 KiB
C#
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace AiSD_Lab1;
|
|
|
|
public class Deque
|
|
{
|
|
Landmark first;
|
|
|
|
public Deque(string data)
|
|
{
|
|
Landmark newEl = new Landmark(data);
|
|
first = newEl;
|
|
}
|
|
|
|
public void AddFirst(string data)
|
|
{
|
|
Landmark newEl = new Landmark(data);
|
|
newEl.next = first;
|
|
first = newEl;
|
|
}
|
|
|
|
|
|
public Landmark RemoveFirst()
|
|
{
|
|
Landmark delEl = first;
|
|
first = delEl.next;
|
|
delEl.next = null;
|
|
return delEl;
|
|
}
|
|
|
|
public void RemoveLast()
|
|
{
|
|
Landmark delEl = first;
|
|
while (delEl.next.next != null)
|
|
{
|
|
delEl = delEl.next;
|
|
}
|
|
delEl.next = null;
|
|
}
|
|
|
|
public void AddLast(string data)
|
|
{
|
|
Landmark newEl = first;
|
|
while (newEl.next != null)
|
|
{
|
|
newEl = newEl.next;
|
|
}
|
|
newEl.next = new Landmark(data);
|
|
}
|
|
|
|
public string GetAll()
|
|
{
|
|
string Deque = "";
|
|
|
|
Landmark curr = first;
|
|
|
|
while (curr.next != null)
|
|
{
|
|
Deque += " " + curr.data;
|
|
curr = curr.next;
|
|
}
|
|
Deque += " " + curr.data;
|
|
|
|
return Deque;
|
|
}
|
|
|
|
} |