Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 28.06.2011, 00:22   #1
naffy
Новичок
Джуниор
 
Регистрация: 28.06.2011
Сообщений: 1
По умолчанию ООП Delphi разработка классов для реализации контейнера на основе структуры"упорядоченный динамический список"

Здравствуйте, форумчане. Помогите кто чем может

Тема:Объектная реализация контейнера на основе комбинированной структуры «Упорядоченный массив динамических очередей»

Нужна разработка, необходимый набор классов БЕЗ программной реализации методов (2 класса как я понимаю:1-упорядоченный массив, 2-очередь)
вот что пока есть:
Код:
unit DoubleLinkedList;

interface

type
DListNode=class(TObject)
private
next,prev:DListNode;
public
constructor create;
destructor destroy; override;
end;

DList=class(TObject)
private
fhead,ftail:DListNode;
fsize:integer;
function getsize:integer;
public
constructor create;
destructor destroy; override;
procedure append(p:DListNode); //Добавление
procedure insertbefore(p,before:DListNode); //вставить перед
procedure remove(p:DListNode); //удалить
procedure delete(p:DListNode); //удалить
function next(p:DListNode):DListNode; //следующий элемент
function prev(p:DListNode):DListNode; //предыдущий эл-нт
published
property size:integer read getsize;
property head:DListNode read fhead;
property tail:DListNode read ftail;
end;

DQueue=class(DList) //FIFO
public
constructor create;
destructor destroy; override;
procedure QueueIn(p:DListNode);
function QueueOut:DListNode;
end;

implementation

uses Sysutils;

type EDoubleLinkedStuff=class(Exception);

constructor DListNode.create;
begin
inherited create;
next:=nil; prev:=nil;
end;

destructor DListNode.destroy;
begin
inherited destroy;
end;

function DList.getsize:integer;
begin
result:=fsize;
end;

constructor DList.create;
begin
inherited create; fhead:=nil; ftail:=nil; fsize:=0;
end;

destructor DList.destroy;
var q:DListNode;
begin
while head < > nil do
begin
q:=fhead; fhead:=fhead.next; q.destroy;
end;
end;

procedure DList.append(p:DListNode);
begin
if fhead=nil then begin
fhead:=p; ftail:=p;
end
else begin
p.prev:=ftail; ftail.next:=p; ftail:=p;
end;
inc(fsize);
end;

procedure DList.insertbefore(p,before:DListNode);
begin
if head=nil then begin
fhead:=p; ftail:=p;
end
else begin
if before=head then begin
p.next:=head; head.prev:=p; fhead:=p;
end
else begin
p.next:=before; p.prev:=before.prev;
p.prev.next:=p; before.prev:=p;
end;
end;
inc(fsize);
end;

procedure DList.remove(p:DListNode);
begin
if p=fhead then begin
fhead:=fhead.next;
if fhead=nil then ftail:=nil
else fhead.prev:=nil;
end
else begin
if p=ftail then begin
ftail:=ftail.prev;
if ftail=nil then fhead:=nil
else ftail.next:=nil;
end
else begin
p.prev.next:=p.next;
p.next.prev:=p.prev;
end;
end;
dec(fsize);
p.next:=nil; p.prev:=nil;
end;

procedure DList.delete(p:DListNode);
begin
remove(p); p.destroy;
end;

function DList.next(p:DListNode):DListNode;
begin
if p=nil then raise EDoubleLinkedStuff.create('next(DList) is nil');
result:=p.next;
end;

function DList.prev(p:DListNode):DListNode;
begin
if p=nil then raise EDoubleLinkedStuff.create('prev(DList) is nil');
result:=p.prev;
end;

constructor DQueue.create;
begin
inherited create;
end;

destructor DQueue.destroy;
begin
inherited destroy;
end;

procedure DQueue.QueueIn(p:DListNode);
begin
insertbefore(p,head);
end;

function DQueue.QueueOut:DListNode;
begin
result:=tail;
if tail < > nil then remove(result);
end;
извиняюсь за длинное сообщение, не нашел как на этом форуме модераторы, подправьте если не лень...


оформляйте код специальным тегом. Кнопка #. Модератор.

Последний раз редактировалось dr.Chas; 28.06.2011 в 18:32.
naffy вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Класс "динамический список" МаргаритKа Помощь студентам 0 23.05.2011 01:08
Как сделать Элемент "список" на основе запроса вертикальным? d_adilet Microsoft Office Access 3 13.05.2011 07:25
программа реализации алгоритма "Сравнение и подсчет" сортировки для АТД «Очередь» (с одной головой) bender_prog Фриланс 7 08.01.2011 01:17
Разработка "рабочего поля" программы сим. эл.схем (Delphi) WaruiOrochi Помощь студентам 4 28.11.2009 21:25
Ищу книгу Андрей Шкрыль "Разработка клиент-серверных приложений в Delphi" virus_t Свободное общение 9 11.08.2009 21:42