Компонентный подход в программировании


         

private static class Node


public interface Queue
{
void put (T o);
T get ();
int size();
} using System;
public interface IQueue
{
void Put (T o);
T Get ();
int Size();
}
public class LinkedQueue
implements Queue
{
public void put (T o)
{
if(last == null)
{
first = last = new Node (o);
}
else
{
last.next = new Node (o);
last = last.next;
}
size++;
}

public T get ()
{
if(first == null) return null;
else
{
T result = first.o;
if(last == first) last = null;
first = first.next;
size--;
return result;
}
}

public int size()
{
return size;
}
private Node last = null;
private Node first = null;
private int size = 0;

private static class Node
{
E o = null;
Node next = null;

Node (E o)
{
this.o = o;
}
}
} public class LinkedQueue
: IQueue
{
public void Put (T o)
{
if(last == null)
{
first = last = new Node (o);
}
else
{
last.next = new Node (o);
last = last.next;
}
size++;
}
public T Get ()
{
if(first == null) return default(T);
else
{
T result = first.o;
if(last == first) last = null;
first = first.next;
size--;
return result;
}
}
public int Size()
{
return size;
}
private Node last = null;
private Node first = null;
private int size = 0;

internal class Node
{
internal E o = default(E);
internal Node next = null;

internal Node (E o)
{
this.o = o;
}
}
}
public class Program
{
public static void main(String[] args)
{
Queue q =
new LinkedQueue();

for(int i = 0; i < 10; i++)
q.put(i*i);

while(q.size() != 0)
System.out.println
("Next element + 1: " +
(q.get()+1));
}
} public class Program
{
public static void Main()
{
Queue q =
new LinkedQueue();

for(int i = 0; i < 10; i++)
q.Put(i*i);

while(q.Size() != 0)
Console.WriteLine
("Next element + 1: " +
(q.Get()+1));
}
}

Содержание  Назад