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

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

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

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 26.06.2011, 13:36   #1
medvedeva
Новичок
Джуниор
 
Регистрация: 26.06.2011
Сообщений: 1
По умолчанию Реализация контейнера на базе очереди. Delphi

нужна помощь в описании используемых классов!
вот всё, что есть, проблема - нужно заменить список на упорядоченный массив, заранее спасибо.
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) //очередь
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:DListNo de);
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(DLi st) is nil');
result:=p.next;
end;

function DList.prev(p:DListNode):DListNode;
begin
if p=nil then raise EDoubleLinkedStuff.create('prev(DLi st) 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;
medvedeva вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Реализация контейнера map. fabregas Общие вопросы C/C++ 11 19.04.2013 16:23
Чем отличается Очередь на базе списка от Очереди на базе массива? TwiX Общие вопросы C/C++ 7 16.02.2011 12:17
Автосигнализация на базе MC-51, реализация проверки правильности кода Lesha_maestro Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 0 23.05.2010 17:08
Реализация очереди! Lazio Помощь студентам 2 08.04.2009 17:41