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


         

private static class Node


public interface Queue <T> { void put (T o); T get (); int size(); } using System;
public interface IQueue <T> { void Put (T o); T Get (); int Size(); } public class LinkedQueue <T> implements Queue <T> { public void put (T o) { if(last == null) { first = last = new Node <T> (o); } else { last.next = new Node <T> (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 <T> last = null; private Node <T> first = null; private int size = 0;
private static class Node <E> {
E o = null; Node<E> next = null;
Node (E o) { this.o = o; } } } public class LinkedQueue <T> : IQueue <T> { public void Put (T o) { if(last == null) { first = last = new Node <T> (o); } else { last.next = new Node <T> (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 <T> last = null; private Node <T> first = null; private int size = 0;
internal class Node <E> {
internal E o = default(E); internal Node <E> next = null;
internal Node <E> (E o) { this.o = o; } } } public class Program { public static void main(String[] args) { Queue<Integer> q = new LinkedQueue<Integer>();
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<int> q = new LinkedQueue<int>();
for(int i = 0; i < 10; i++) q.Put(i*i);
while(q.Size() != 0) Console.WriteLine ("Next element + 1: " + (q.Get()+1)); } }
Пример 10.1.
Закрыть окно



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