Saturs
Uzdevuma nostādne............................. 4
Teorētiskais pamatojums.................. 4
Apstrādes operācijas..................... 5
Datu struktūras modelis.................. 6
Programmas apraksts...................... 8
Programmas struktūra..................... 8
Ievaddati................................ 8
Izvaddati................................ 9
Instrukcija lietotājam................... 9
Kontrolpiemēra analīze.................. 11
Secinājumi.............................. 14
Literatūras saraksts.................... 15
Pielikums- programmas nekompilēts teksts 16
Uzdevuma nostādne
Dati- formalizētā veidā attēlota
tekstuālā, skaitliskā, grafiskā, video- un audio informācija, kuru lietotājs
vai datu apstrādes ierīces var interpretēt, apstrādāt vai pārsūtīt. Datu tipi
var būt gan skalāri, gan strukturāli.
Datu struktūra- datu organizācijas
veids un raksturs, iespējamo vērtību un operāciju kopums, tā ir jebkuram
informacionālam objektam piemītoša īpašība. Datu struktūras ir jebkuras
programmēšanas valodas obligāta sastāvdaļa- tās galvenokārt izmanto skalāras
datu struktūras. Izšķir operacionālas, failu, fundamentālas, saistītas un
nesaistītas, statistiskās, pusstatistiskās un dinamiskās, sakārtotas un
nesakārtotas datu struktūras.
Operacionālas datu struktūras- datu
struktūras, kuras tiek izveidotas, glabātas un apstrādātas pamatatmiņā.
Failu datu struktūras- dati tiek
glabāti diska atmiņā. Tās pamatelements ir ieraksts.
Fundamentālas datu struktūras- dati
ar sarežģītu uzbūvi, datu tips ir strukturēts.
Saraksts- lineāra datu struktūra, kurā katrs
iepriekšējais elements ir saistīts ar nākamo, izņēmums ir pirmais un pēdējais
elements.
Divkāršsaistīts saraksts- saraksts,
kurā katram elementam ir gan priekštecis, gan pēctecis (izņemot pirmo un pēdējo
elementu).
Pašorganižēts saraksts- saraksts, kurā
jauns elements tiek pievienots saraksta
beigās un tas kļūst par tekošo.
Otrais sakārtošanas paņēmiens-
lietojot operācijas Retrive (nolasīt), Update (labot), Findkey (meklēt pēc
atslēgas), Findith (meklēt pēc kārtas numura) apstrādātais elements pārvietojas
pa vienu vietu uz saraksta augšpusi.
Lai organizētu darbu ar sarakstiem lieto
dažādas apstrādes operācijas. Izšķir trīs vedu operācijas:
1. Servisoperācijas:
·
Create- izveido jaunu tukšu
sarakstu,
·
Terminate- likvidē sarakstu un tā
visus ierakstus,
·
Size- tekošo elementu skaita noteikšana,
·
CurPos- tekošā elementa kārtas
numura noteikšana.
·
Empty- pārbauda vai saraksts ir
tukšs,
·
Full- pārbauda vai saraksts ir
pilns,
·
IsFirst- pārbauda vai tekošais
elements ir pirmais sarakstā,
·
IsLast- pārbauda vai tekošais
elements ir pēdējais sarakstā.
2. Meklēšanas operācijas:
·
FindNext- ja tekošais elements jau
nav pēdējais sarakstā, tad sameklē tā pēcteci,
·
FindPrior- ja tekošais elements
jau nav pirmais sarakstā, tad sameklē tā priekšteci,
·
FindIth- sameklē sarakstā elementu
ar kārtas numuru “I”,
·
FindFirst- sameklē pirmo elementu
sarakstā,
·
FindLast- sameklē pēdējo elementu
sarakstā.
3. Apstrādes operācijas:
·
Insert- pievieno saraksta beigās
jaunu elementu un tas kļūst par tekošo,
·
Update- ļauj labot tekošā elementa
datu un atslēgas laukus,
·
Delete- dzēš tekošo elementu,
·
ShowEm- parāda uz ekrāna visus
saraksta elementus.
Head
nil
. . .
. . .
1 2 N
Current 2 Teil
Lietojot divkāršsaistītu sarakstu ir vieglāk
veikt un projektēt dažādas operācijas, jo saraksts satur rādītājus, kas norāda
uz tekošā elementa priekšteci un pēcteci. Tādā veidā kļūst vienkāršāka pieeja
šiem datu laukiem un var panākt funkciju un procedūru efektīvāku izpildi un
samazināt laiku, kas nepieciešams šo darbību veikšanai.
Divkāršsaistīta saraksta trūkumi: jādefinē
papildus lauki, kas palielina saraksta apjomu datora atmiņā, jāveic nedaudz
sarežģītākas operācijas programmējot procedūras Insert un Delete.
Programmas lietotājam arī ir vieglāk strādāt
ar šo programmu, jo viņš var brīvi pārvietoties pa sarakstu no viena elementa
uz otru.
Programmā definētie un
lietotie tipi.
Const
MaxSize=19; {vai jebkurš cits lielāks skaitlis}
Type
Count=0..MaxSize; {numurs}
Position=1..Maxsize; {pozīcija}
DataType=String[30]; {datu tips- jebkurš tips}
KeyType=String[5]; {atslēgas lauka tips jebkurš
ordinārs tips vai string}
StdElem=Record
{elements kā ieraksts ar datu un atslēgas laukiem}
Data:DataType; {saraksta datu lauks}
Key:KeyType;
{saraksta atslēglauks}
End;
Node=^TNode; {rādītājs}
TNode=Record {ieraksts ar rādītājiem uz elementa
priekšteci un pēcteci}
elem:StdElem;
next:Node;
prior:Node;
End;
List=^ListInstance; {saraksta rādītājs}
ListInstance=Record {saraksta struktūra}
Current:Node;
{rādītājs uztekošo elementu}
ICurrent:Count;
{tekošā elementa kārtas numurs}
N:Count; {pēdējā
elementa kārtas numurs}
Head:Node;
{rādītājs uz pirmo elementu sarakstā}
Tail:node; {rādītājs uz beidzamo elementu sarakstā}
End;
Programmas apraksts
Studiju darba datu struktūrās programma divkāršsaistīta saraksta realizācijai- Zvaigznīšu brīdis ir uzrakstīta programmēšanas valodā Pascal 7.01. Programma
sastāv no visām šādam sarakstam nepieciešamām pamat- funkcijām un procedūrām,
ir realizētas arī daudzveidīgas meklēšanas operācijas. Ir izveidotas
procedūras, kuras nodrošina lietotājam viegli uztveramu un patīkamu interfeisu.
Ar Asemblera palīdzību tradicionālo datora pamatkrāsu vietā ir izveidotas citas
krāsas, kuras uzlabo interfeisu un padara programmu savā ziņā par unikālu.
Programmas visas funkcijas, procedūras un
galvenā daļa (Begin-End) atrodas vienā failā.
Programma
satur:
º 27 procedūras, kuras nodrošina saraksta operāciju funkcionēšanu un
interfeisu lietotājam, ir arī procedūras, kuras nepieciešamas citu procedūru
darbībai,
º 6 funkcijas, no kurām viena ietilpst procedūrā laiks, un tā ir nepieciešama pareiza laika nepārtrauktai
nolasīšanai un aprēķināšanai,
º asemblera tekstu, kas uzģenerē vēlamās krāsas,
º programmas galveno daļu, kas attiecīgajā brīdī izsauc vajadzīgās
procedūras vai funkcijas un nodrošina interfeisu.
Šī programma var apstrādāt jebkura veida
tekstuālus vai cipariskus datus. Sākot darbu ar programmu Zvaigznīšu brīdis lietotājs var izvēlēties kādus datus viņš grib
apstrādāt. Datus var ievadīt ar operatora Insert
palīdzību. Katram elementam jāievada datu lauks un unikāla atslēga, kas var būt
gan teksts, gan cipari un pēc kuras doto elementu var identificēt un sameklēt.
Programma neļauj ievadīt divas vienādas atslēgas. Datu lauka maksimālais
pieļaujamais garums ir 30 simboli, bet atslēglauka garums nevar pārsniegt 5
simbolus, pretējā gadījumā atslēglauks tiek automātiski saīsināts. Pēc ievades
ar šiem datiem brīvi var veikt visas operācijas, lai iegūtu vēlamo rezultātu.
Programmas izvaddati tiek atspoguļoti
tabulas veidā. Tie ir atkarīgi no tā kādi dati tika ievadīti un kādas šo datu
apstrādes operācijas tika veiktas. Izvaddatus programmas lietotājs redz visu
programmas darbības laiku. Tas ļauj ērti veikt operācijas un uzreiz redzēt
izpildes rezultātu. Programmas gaitā lietotājam tiek izvadīti ziņojumi par to,
kas attiecīgajā brīdī jādara vai kļūdu ziņojumi ar norādēm uz tālāko darbību
nepieciešamību.
Programmas Zvaigznīšu brīdis lietotājam, palaižot failu zvaigzn.exe, parādās
izveidots tukšs saraksts tabulas veidā ar izvēlni, no kuras var izvēlētie
darbības, kuras jāveic, lai iegūtu vēlamo rezultātu. Izvēlnē katrai operācijai
ir izgaismots kāds burts. Izvēli var veikt uzejot ar virzienbultiņu palīdzību uz vēlamās
operācijas un nospiežot Enter. Vai
arī pastāv otrs veids- jānospiež uz klaviatūras burtu daļas kāds no burtiem,
kurš ir izcelts izvēlnes attiecīgajam operatoram.
Programmas izvēlne satur šādas operācijas:
º Insert- pievienot jaunu elementu,
º Delete- dzēš tekošo elementu,
º Update- labo tekošo elementu,
º IsFull- pārbauda vai saraksts ir pilns un izvada ziņojumu,
º IsEmpty- pārbauda vai saraksts ir tukšs un izvada ziņojumu,
º Last- atrod sarakstā pēdējo elementu un tas kļūst par tekošo,
º First- atrod sarakstā pirmo elementu un tas kļūst par tekošo,
º FindKey- meklē elementu pēc ievadītās atslēgas, pēc atrašanas šis
elements kļūst par tekošo,
º IsFirst- pārbauda vai tekošais elements ir pirmais sarakstā un izvada
ziņojumu,
º IsLast- pārbauda vai tekošais elements ir pēdējais sarakstā un izvada
ziņojumu,
º Prior- ja tekošais elements jau nav pirmais sarakstā, tad atrod tā
priekšteci un tas kļūst par tekošo,
º Next- ja tekošais elements jau nav pēdējais sarakstā, tad atrod tā
pēcteci un tas kļūst par tekošo,
º FindIth- meklē elementu pēc ievadītā kārtas numura, un atrastais
elements kļūst par tekošo,
º Empty- izdzēš esošo sarakstu,
º Exit- diemžēl beidz darbu ar programmu Zvaigzn.
Šī
programma lietotājam ir viegli uztverama un labi apgādāta ar ziņojumiem, kas
vienmēr informē par to, kas attiecīgajā brīdī jādara vai kāds taustiņš jāspiež.
Kontrolpiemēra analīze
Kā
piemēru apskatīsim sarakstu, kas satur cilvēku vārdus un uzvārdus, un
atslēglaukus, kas identificē katru datu lauku.
![]() |
Palaižot programmu Zvaigznīšu brīdis, parādās izvēlne, tukšs saraksta logs un laikrādis:
1. attēls- Sākuma logs.
Jaunu elementu pievienošana- jāievada dati un atslēga:
2. attēls- Elementu pievienošanas logs
Kļūdas ziņojums par vienādām atslēgām:
3. attēls- Ziņojums par nekorektu datu ievadi
Ziņojumi par saraksta apjomu:
4. attēls- Ziņojums, ka saraksts vēl nav pilns
5. attēls- Ziņojums, ka saraksts ir pilns
![]() |
Saraksts ar elementiem un iezīmētu tekošo elementu:
6. attēls- Saraksta ar elementiem logs
Ziņojumi par tekošā elementa atrašanās vietu sarakstā:
7.
attēls- Ziņojums par to, vai tekošais elements ir pirmais sarakstā
8. attēls- Ziņojums par to, vai tekošais
elements ir pēdējais sarakstā
Meklēšanas pēc atslēgas:
9. attēls- Meklējamās atslēgas ievades logs
10. attēls- Meklēšanas pēc atslēgas rezultāta logs
Meklēšanas pēc kārtas numura:
11. attēls- Meklēšanas pēc kārtas numura logs
Kļūdu ziņojumi:
12. attēls- Kļūdu ziņojums
Saraksta
likvidēšana:
13. attēls- Saraksta likvidēšanas logs
![]() |
Pareiza laika rādīšanas logs:
13. attēls- Pulkstenis
Secinājumi
Studiju darba
datu struktūrās rezultāti ir atbilstoši prasītajiem. Ar šīs programmas
palīdzību var apstrādāt datus un iegūt vajadzīgos rezultātus. Projektā tika realizētas
procedūras, kuras vēl vairāk uzlabo darba efektivitāti un lietošanas ērtumu.
Programma tika veidota tā, lai lietotājam nebūtu nekādu problēmu ar darbību un
operāciju izpildi. Programmā tika mēģināti realizēt visefektīvākie operāciju
izpildes algoritmi, taču no šī studiju darba es sapratu, ka visefektīvākos
algoritmus ir grūti un sarežģīti projektēt, un priekš šādas programmas varbūt
arī nebija nepieciešams veltīt maksimālas pūles un laiku ideālu algoritmu
izstrādei.
Programmējot
valodā Pascal radās problēmas ar latviešu alfabēta burtu atainošanu. Samērā
grūti, bet interesanti bija radīt šādu unikālu interfeisu Dos vidē.
Literatūras saraksts
Skaidrojošā vārdnīca “Personālie datori”
G. Matisona lekciju konspekts (1998)
Internets
Pielikums- programmas nekompilēts teksts
uses crt,dos;
Const
MaxSize=19;
m:array[1..15] of string =
(' Insert ',' Delete ',' Update ',' IsFull ',
' IsEmpty',' Last ',' First ',' FindKey',' IsFirst',
' IsLast ',' Prior ',' Next ',' FindIth',
' Empty ',' Exit ');
Type
Count=0..MaxSize;
Position=1..Maxsize;
DataType=String[30];
KeyType=String[5];
StdElem=Record
Data:DataType;
Key:KeyType;
End;
Node=^TNode;
TNode=Record
elem:StdElem;
next:Node;
prior:Node;
End;
List=^ListInstance;
ListInstance=Record
Current:Node;
ICurrent:Count;
N:Count;
Head:Node;
Tail:node;
End;
Var
C:Char;
Lst:List;
E,main:Stdelem;
P:Pointer;
S:String;
Z:integer;
procedure Laiks;
type St2=String[2];
var h,mn,s,s100:word;st:string;
function mmx(w:word):st2;
var st:st2;
begin
Str(w:0,st);
if byte(st[0])=1 then st:='0'+st;
mmx:=st;
end;
begin
window(64,23,77,23);textbackground(cyan);clrscr;
Window(66,23,75,23);
textbackground(black);clrscr;
repeat
gotoxy(1,1);
gettime(h,mn,s,s100);
write(' ',mmx(h));textcolor(white+blink);
write(':');normvideo;write(mmx(mn));
textcolor(white+blink);write(':');normvideo;write(mmx(s));
until keypressed;
end;
procedure him;
var i,m,k:integer;
begin
randomize;
for i:=1
to 80 do
for
k:=1 to 24 do
begin
textcolor(random(15));
gotoxy(i,k);
Write('*');end;
for i:=1 to 79 do begin
gotoxy(i,25);textcolor(random(15));write ('*');end;end;
procedure virsr;
var i:integer;
begin
window(1,1,80,1);textbackground(5);clrscr;highvideo;textcolor(red);
write('
Zvaigzniishu briidis');
if keypressed then begin
gotoxy(49,1);textcolor(Random(16));write(' * ');
gotoxy(53,1);textcolor(random(16));write(' * ');
gotoxy(57,1);textcolor(Random(16));write(' * ');
gotoxy(10,1);textcolor(random(16));write(' *');
gotoxy(14,1);textcolor(Random(16));write('
*');
gotoxy(18,1);textcolor(Random(16));write(' *');
i:=i+1; end;
end;
Procedure Wdone(var P:pointer);
begin
window(1,1,80,25);
move
(P^,mem[$b800:0000],80*25*2);
End;
Function Full(L:List):Boolean;
Begin
Full:=(L^.N=MaxSize);
End;
Function Empty(L:List):Boolean;
Begin
Empty:=(L^.N=0);
End;
Function IsFirst (L:List):Boolean;
Begin
If Not
Empty(L) then
IsFirst:=L^.ICurrent=1
else
IsFirst:=True;
End;
Function IsLast (L:List):Boolean;
Begin
If Not
Empty(L) then
IsLast:=L^.ICurrent=L^.N
else
Islast:=True;
End;
Procedure Create(Var L:List);
Begin
New(L);
With L^ do
Begin
Head:=nil;
Tail:=nil;
Current:=nil;
N:=0;
ICurrent:=0;
End;
End;
Procedure Terminate(Var L:List);
var
I:Count;
T:Node;
Begin
With L^ do
Begin
Current:=Head;
For I:=1
to N do
Begin
T:=Current;
Current:=Current^.next;
Dispose(T);
End;
End;
Dispose(L);
End;
Procedure FindFirst(Var L:list);
Begin
L^.Current:=L^.Head;
If not
Empty(L) then
L^.ICurrent:=1
else
L^.ICurrent:=0;
End;
Procedure FindLast(Var L:List);
Begin
With L^ do
Begin
Current:=Tail;
Icurrent:=n;
End;
End;
Procedure Findnext(var L:List);
Begin
If not
empty (L) then
With L^ do
If
Icurrent
Begin
Icurrent:=Icurrent+1;
Current:=Current^.Next;
End;
End;
Procedure FindPrior(Var L:List);
Begin
If not
empty (L) then
With L^ do
If
Icurrent>1 then
Begin
Icurrent:=Icurrent-1;
Current:=Current^.Prior;
End;
End;
Procedure Insert(Var L:List;E:StdElem);
var T:Node;
Begin
If not
Full(L) Then
With L^ do
Begin
FindLast(L);
New(T);
If Empty(L)
then Head:=T
else
Current^.next:=T;
T^.prior:=Current;
T^.Next:=Nil;
T^.Elem:=E;
Current:=T;
Tail:=T;
N:=N+1;
Icurrent:=N;
End;
End;
Procedure ProgWin;
var I:Integer;
Begin
asm
Mov Ax,1010h
Mov Bx,06
Mov Ch,37
Mov Cl,48
Mov Dh,57
Int 10h
end;
asm
Mov Ax,1010h
Mov Bx,blue
Mov Ch,32
Mov Cl,32
Mov Dh,32
Int 10h
end;
asm
Mov Ax,1010h
Mov Bx,05
Mov Ch,38
Mov Cl,38
Mov Dh,38
Int 10h
End;
asm
Mov Ax,1010h
Mov Bx,cyan
Mov Ch,86
Mov Cl,152
Mov Dh,136
Int 10h
End;
asm
Mov Ax,1010h
Mov Bx,02
Mov Ch,18
Mov Cl,17
Mov Dh,18
Int 10h
End;
window(1,1,80,25);textbackground(white);clrscr;
him;
window(2,2,61,24);textcolor(2);
Textbackground(blue);
Writeln('ÉĶĶĶĶĖĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĖĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶ»');
writeln('ŗ
NR ŗ DATA ŗ KEY
ŗ');
writeln('ĢĶĶĶĶĪĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĪĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶ͹');
For I:=1
to 19 do
Writeln('ŗ ŗ ŗ ŗ');
Write('ČĶĶĶĶŹĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶŹĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶͼ');
End;
procedure Winit(x1,y1,x2,y2:integer;S:String;var
P:pointer);
begin
Getmem(P,80*25*2);
move
(mem[$b800:0000],P^,80*25*2);
Window(1,1,80,25);
window(x1+2,y1+1,x2+2,y2+1);textbackground(cyan);clrscr;
Window(x1,y1,x2,y2);textbackground(5);
clrscr;
End;
Procedure ShowEm(Var L:list);
Var T:Node;
I:Count;
Begin
window(3,5,58,24);
textattr:=2;
textbackground(blue);
If Not
empty(L) then
With L^ do
Begin
T:=Head;
I:=1;
While
T<>Nil do
Begin
If
Icurrent = I then
textAttr:=112 else
Begin
textattr:=2;
textbackGround(blue);
End;
Write(I:2,' ŗ ',T^.elem.data:32,'
ŗ ',T^.elem.key:14,' ');
T:=T^.Next;
I:=I+1;
End;
End
else
Writeln(' ŗ Saraksts tukss!');
textAttr:=2;
End;
Procedure Delete(Var L:List);
var T:Node;
Begin
If not
Empty(L) then
with L^ do
Begin
If (not
IsFirst(L)) and (not IsLast(L)) then
Begin
{Nav ne pedejais ne pirmais}
Current^.next^.prior:=Current^.prior;
Current^.prior^.next:=Current^.next;
T:=current;
current:=current^.next;
N:=N-1;
Dispose(T);
End
else
Begin
If
IsFirst(L) then
Begin
{Pirmais}
If
Islast(L) then
Begin {Pirmais un pedejais}{vienigais}
Dispose(Current);
Current:=nil;
Head:=nil;
Tail:=nil;
Icurrent:=0;
n:=0;
End
else
begin {Tikai pirmais}
Head:=Current^.next;
T:=Current;
Current:=Current^.next;
Current^.prior:=nil;
N:=N-1;
Dispose(T);
End;
End
else
Begin
{tikai Pedejais}
T:=Current;
Current:=Current^.Prior;
Current^.next:=nil;
Tail:=Current;
N:=N-1;
Icurrent:=Icurrent-1;
Dispose(T);
End;
End;
End;
End;
Function GoodKey(var L:list; K:String):Boolean;
var F:boolean; {found}
i:Count;
T:Node;
begin
with L^ do
begin
F:=False;
T:=Head;
For I:=1
to N do
begin
If
T^.elem.key=K then F:=true;
T:=T^.next;
End;
Goodkey:=not F;
End;
end;
Procedure MyMessage(Title,Message:String);
var P:Pointer;
l:Byte
absolute Message;
Min,Max:Word;
Begin
TextColor(2);
TextBackGround(0);
Min:=Windmin;
Max:=WindMax;
Winit(3,11,57,12,Title,P);
Gotoxy(30-l
shr 1,1);
Write(Message);
Gotoxy(20,2); Write('
Nospiediet jebkuru taustinju ');
Readkey;
WDone(P);
Window(lo(min)+1,hi(min)+1,lo(max)+1,hi(max)+1);
TextAttr:=2;
End;
procedure cur(flag:boolean);
const sizecursor:word=0;
var reg:registers;
begin
with reg do
begin if flag then begin
cx:=sizecursor;
end
else
begin
BH:=0;
AH:=03;
intr($10,reg);
sizecursor:=Cx;
ch:=$20;
end;
ah:=01;
intr($10,reg);
end;end;
Procedure EmptyMsg;
Begin
MyMessage('Kluda!','Ar tukshu sarakstu nav iespeejams izpldiit sho
darbiibu!');
End;
Procedure MyFindKey(L:List);
var K
:string;
Found :Boolean;
T :Node;
I :Count;
W :Pointer;
Begin
WInit(10,10,50,10,'Find Key',P);
textcolor(black);
Write('Enter Key:');
Readln(K);
WDone(P);
Found:=False;
With L^ do
Begin
T:=Head;
For I:=1
to N do
Begin
If
T^.elem.Key=K then
Begin
Found:=True;
Current:=T;
Icurrent:=I;
break;
End;
T:=T^.next;
End;
End;
If Found
then MyMessage('FindKey','Atsleega ir atrasta!') else
MyMessage('FindKey','Shaadas atsleegas sarakstaa nav!');
if lst^.current<>lst^.head then
begin
showem(lst);delay(1333);
main:=lst^.Current^.prior^.elem;
lst^.Current^.prior^.elem:=lst^.current^.elem;
lst^.Current^.elem:=main;findprior(lst);end;
End;
Procedure EditElem(Var L:List;Var
E:StdElem;F:Boolean);
var W:Pointer;
S:String;
Lastkey:KeyType;
MustRep:Boolean;
begin
cur(true);
If F then
Begin
S:='Insert';
E.Data:='';
E.Key:='';
End
else
S:='Edit';
WInit(10,12,50,13,S,W);
Gotoxy(1,1);textcolor(2);
Writeln('
Data: ');
Write('
Key : ');
GotoXY
(1,1);
Write (' Data: ');
Readln(E.Data);
Repeat
gotoxy(1,2);Clreol;
gotoxy(1,2);
Write (' Key : ');
LastKey:=E.key;
Readln(E.Key);
if
((S='Insert') and (not Goodkey(L,E.Key))) or ((S='Edit') and (not
Goodkey(L,E.Key)) and (E.key<>Lastkey)) then
Begin
MyMessage('Error','Taada atsleega jau eksistee!!!');
MustRep:=True;
End
else
MustRep:=False;
Until
(MustRep=False) ;
WDone(W);
cur(false);
End;
procedure MakeEmpty(var L:List);
Begin
While not
Empty(L) do Delete(L);showem(lst);
End;
Procedure WInsert(var lst:list);
var
E:Stdelem;
Begin
If not
Full(lst) then
Begin
EditElem(Lst,E,True);
Insert(Lst,E);
End else
MyMessage('','Saraksts jau ir pilns!');
End;
Procedure WDelete(var Lst:List);
Begin
If not
Empty(lst) then
Begin
Delete(Lst);
window(3,4,57,21);
textcolor(black);
textbackground(blue);
Clrscr;
window(3,2,57,24);
End else
Emptymsg;
End;
Procedure Wedit(var Lst:List);
var L:list;
Begin
If not
Empty(lst) then
Begin
cur(true);
E:=lst^.Current^.elem;
EditElem(Lst,E,False);
lst^.Current^.elem:=E;
End
else begin Emptymsg; cur(false);end;
if lst^.current<>lst^.head then
begin
showem(lst);delay(1333);
main:=lst^.Current^.prior^.elem;
lst^.Current^.prior^.elem:=lst^.current^.elem;
lst^.Current^.elem:=main;findprior(lst);end;
End;
Procedure FindIth(var lst:list);
var W:Pointer;
S:String;
Num,I:Integer;
begin
textcolor(black);
If not
empty(lst) then
with lst^
do
begin
Winit(20,10,50,10,'FindIth',W);
Write('Ievadiet nummuru:');
Readln(s);
Val(S,Num,I);
Wdone(W);
If
(I<>0) or (Num<1) or (Num>n) then Mymessage('Kljuuda','Nepareizs
Nummurs!')
else
Begin
findFirst(Lst);
For
I:=1 to Num-1 do FindNext(Lst);
End;
end
else
begin EmptyMsg;end;
if lst^.current<>lst^.head then
begin
showem(lst);delay(1333);
main:=lst^.Current^.prior^.elem;
lst^.Current^.prior^.elem:=lst^.current^.elem;
lst^.Current^.elem:=main;findprior(lst);end;
End;
procedure izvele;
var i,r:integer;
begin
window(64,4,74,18);textbackground(cyan);clrscr;
for i:=1 to 3 do
begin write(' ');textcolor(red);
write(m[i][2]);textcolor(black);lowvideo;
for r:=3 to 8 do begin
write(m[i][r]);end;if
i<>15 then writeln;
end;
textcolor(black);write(' ');for r:=1 to 3 do
write(m[4][r]);
textcolor(red);write(m[4][4]);textcolor(black);for
r:=5 to 8 do write(m[4][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 3 do
write(m[5][r]);
textcolor(red);write(m[5][4]);textcolor(black);for
r:=5 to 8 do write(m[5][r]);
writeln;
textcolor(black);write(' ');
textcolor(red);write(m[6][2]);textcolor(black);for
r:=3 to 8 do write(m[6][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 2 do
write(m[7][r]);
textcolor(red);write(m[7][3]);textcolor(black);for
r:=4 to 8 do write(m[7][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 5 do
write(m[8][r]);
textcolor(red);write(m[8][6]);textcolor(black);for
r:=7 to 8 do write(m[8][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 5 do
write(m[9][r]);
textcolor(red);write(m[9][6]);textcolor(black);for
r:=7 to 8 do write(m[9][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 5 do
write(m[10][r]);
textcolor(red);write(m[10][6]);textcolor(black);for
r:=7 to 8 do write(m[10][r]);
writeln;
textcolor(black);write(' ');
textcolor(red);write(m[11][2]);textcolor(black);for
r:=3 to 8 do write(m[11][r]);
writeln;
textcolor(black);write(' ');
textcolor(red);write(m[12][2]);textcolor(black);for
r:=3 to 8 do write(m[12][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 6 do
write(m[13][r]);
textcolor(red);write(m[13][7]);textcolor(black);write(m[13][8]);
writeln;
textcolor(black);write(' ');for r:=1 to 2 do
write(m[14][r]);
textcolor(red);write(m[14][3]);textcolor(black);for
r:=4 to 8 do write(m[14][r]);
writeln;
textcolor(black);write(' ');for r:=1 to 2 do
write(m[15][r]);
textcolor(red);write(m[15][3]);textcolor(black);for
r:=4 to 8 do write(m[15][r]);
end;
procedure sakums;
var i,r:integer;
begin
cur(false);
showem(lst);
window(33+30,3,49+30,21);textbackground(black);clrscr;
window(61,2,77,20);textbackground(cyan);clrscr;textcolor(black);
for i:=1 to 17 do begin
highvideo;textcolor(yellow);
gotoxy(3,i+1);writeln('*');delay(20);
gotoxy(3,i+1);textcolor(black);writeln('*');
textcolor(yellow);
gotoxy(15,19-i);writeln('*');delay(20);
textcolor(black);gotoxy(15,19-I);writeln('*');
end;
for i:=1 to
7 do begin
highvideo;
textcolor(yellow);gotoxy(17-2*i,2);write('*');delay(20);
textcolor(black);
gotoxy(17-2*i,2);write('* ');
textcolor(yellow);gotoxy(2*i+1,18);write('*');delay(20);
textcolor(black);
gotoxy(2*i+1,18);write('* ');
end;
izvele;
window(65,z,73,z);textbackground(red);clrscr;
textcolor(red);highvideo;write(' ',m[z-3][2]);
textcolor(black);lowvideo;
for r:=3 to 8 do write(m[z-3][r]);laiks;i:=80;
repeat
virsr; c:=readkey;
case c of
#80: begin z:=z+1;i:=i-1;if z>18 then z:=4;
textcolor(black);
izvele;
gotoxy(1,z-4);window(65,z,73,z);textbackground(red);clrscr;
if z=7
then begin
textcolor(black);for r:=1 to 3 do write(m[4][r]);
textcolor(red);highvideo;
write(m[4][4]);textcolor(black);lowvideo;for r:=5 to 8 do
write(m[4][r]);end else
if z=8
then begin
textcolor(black);for r:=1 to 3 do write(m[5][r]);
textcolor(red);highvideo;
write(m[5][4]);textcolor(black);lowvideo;for r:=5 to 8 do
write(m[5][r]);end else
if z=10
then begin
textcolor(black);for r:=1 to 2 do write(m[7][r]);
textcolor(red);highvideo;
write(m[7][3]);textcolor(black);lowvideo;for r:=4 to 7 do
write(m[7][r]);end else
if z=11
then begin
textcolor(black);for r:=1 to 5 do write(m[8][r]);
textcolor(red);highvideo;
write(m[8][6]);textcolor(black);lowvideo;for r:=7 to 8 do write(m[8][r]);end
else
if z=12
then begin
textcolor(black);for r:=1 to 5 do write(m[9][r]);
textcolor(red);highvideo;
write(m[9][6]);textcolor(black);lowvideo;for R:=7 to 8 do
write(m[9][r]);end else
if z=13
then begin
textcolor(black);for r:=1 to 5 do
write(m[10][r]);
textcolor(red);highvideo;
write(m[10][6]);textcolor(black);lowvideo;for r:=7 to 8 do
write(m[10][r]);end else
if z=16
then begin
textcolor(black);for r:=1 to 6 do write(m[13][r]);
textcolor(red);highvideo;
write(m[13][7]);textcolor(black);lowvideo;write(m[13][8]);end else
if z=17 then begin
textcolor(black);for r:=1 to 2 do write(m[14][r]);
textcolor(red);highvideo;
write(m[14][3]);textcolor(black);lowvideo;for r:=4 to 8 do
write(m[14][r]);end else
if z=18
then begin
textcolor(black);for r:=1 to 2 do write(m[15][r]);
textcolor(red);highvideo;
write(m[15][3]);textcolor(black);lowvideo;for r:=4 to 8 do
write(m[15][r]);end else
begin
textcolor(red);highvideo;write(' ',m[z-3][2]);
textcolor(black);lowvideo;
for r:=3 to 8 do write(m[z-3][r]);end;laiks;
end;
#73: begin
cur(true);winsert(lst);cur(false);showem(lst);sakums;end;
#68: begin
wdelete(lst);progwin;showem(lst);z:=5;sakums;end;
#85: begin wedit(lst);showem(lst);laiks;end;
#70: begin If Full(Lst) then
Mymessage('Full','Saraksts ir pilns!')
else Mymessage('Full','Saraksts nav pilns!');laiks;end;
#69: begin If Empty(Lst) then
Mymessage('Empty','Saraksts ir tukshs')
else Mymessage('Empty','Saraksts nav tukshs!');laiks;end;
#76: begin FindLast(lst);showem(lst);laiks;end;
#105: begin findfirst(lst);showem(lst);laiks;end;
#75: begin If not Empty(lst) then MyFindKey(Lst)
else EmptyMsg;showem(lst);laiks;end;
#114: begin if Not Empty(lst) then begin
If IsFirst(lst) then
Mymessage('IsFirst','Elements ir pirmais sarakstaa!') else
Mymessage('IsFirst','Elements nav pirmais sarakstaa!');
end else EmptyMsg; laiks;end;
#115: begin if Not Empty(lst) then begin
If IsLast(Lst) then Mymessage('IsLast','Elements ir peedeejais
sarakstaa!') else
Mymessage('IsLast','Elements nav peedeejais sarakstaa!');
end else EmptyMsg;laiks;end;
#80: begin
findprior(lst);showem(lst);sakums;laiks;end;
#78: begin findnext(lst);showem(lst);laiks;end;
#116: begin FindIth(lst);showem(lst);laiks;end;
#109: begin if Not Empty(lst) then
Begin
MakeEmpty(lst);
window(3,4,58,21);textbackground(blue);
Clrscr;
window(3,22,55,24);
MyMessage('Empty','Saraksts
ir izdzeests!');
End else
EmptyMsg;progwin;z:=17;sakums;end;
#120: begin
Terminate(Lst);Window(1,1,80,25);textattr:=15;clrscr;halt;end;
#13: begin
if
(z=4) then begin cur(true);
winsert(lst);cur(false);showem(lst);sakums;end;
if
(z=5) then begin
wdelete(lst);progwin;
showem(lst);z:=5;sakums;end;
if
(z=6) then begin
wedit(lst);showem(lst);laiks;end;
if
(z=7) then begin
If Full(Lst) then
Mymessage('Full','Saraksts ir pilns!')
else
Mymessage('Full','Saraksts nav pilns!');laiks;end;
if
(z=8) then begin
If Empty(Lst) then
Mymessage('Empty','Saraksts ir tukshs')
else
Mymessage('Empty','Saraksts nav tukshs!');laiks;end;
if
(z=9) then begin
FindLast(lst);showem(lst);laiks;end;
if
(z=10) then begin
findfirst(lst);showem(lst);laiks;end;
if
(z=11) then begin
If not Empty(lst)
then MyFindKey(Lst)
else EmptyMsg;showem(lst);laiks;end;
if
(z=12) then begin
if Not Empty(lst)
then begin
If IsFirst(lst) then
Mymessage('IsFirst','Elements ir pirmais sarakstaa!') else
Mymessage('IsFirst','Elements nav
pirmais sarakstaa!');
end else EmptyMsg;
laiks;end;
if
(z=13) then begin
if Not Empty(lst)
then begin
If IsLast(Lst) then
Mymessage('IsLast','Elements ir peedeejais sarakstaa!') else
Mymessage('IsLast','Elements nav peedeejais sarakstaa!');
end else
EmptyMsg;laiks;end;
if
(z=14) then begin
findprior(lst);showem(lst);laiks;end;
if
(z=15) then begin
findnext(lst);showem(lst);laiks;end;
if
(z=17) then begin
if Not Empty(lst)
then
Begin
MakeEmpty(lst);
window(3,4,56,21);textbackground(blue);
Clrscr;
window(3,22,55,24);
MyMessage('Empty','Saraksts ir izdzeests!');
End else
EmptyMsg;progwin;z:=17;sakums;end;
if
(z=16) then begin
FindIth(lst);showem(lst);laiks;end;
if
(z=18) then begin
Terminate(Lst);
Window(1,1,80,25);
textattr:=15;
clrscr;halt;end;
end;
#72: begin z:=z-1;i:=i+1;if z<4 then z:=18;
textcolor(black);
izvele;gotoxy(1,z-3);
window(65,z,73,z);textbackground(red);clrscr;
if z=7
then begin
textcolor(black);for r:=1 to 3 do write(m[4][r]);
textcolor(red);highvideo;
write(m[4][4]);textcolor(black);lowvideo;for r:=5 to 8 do
write(m[4][r]);end else
if z=8
then begin
textcolor(black);for r:=1 to 3 do write(m[5][r]);
textcolor(red);highvideo;
write(m[5][4]);textcolor(black);lowvideo;for r:=5 to 8 do
write(m[5][r]);end else
if z=10
then begin
textcolor(black);for r:=1 to 2 do write(m[7][r]);
textcolor(red);highvideo;
write(m[7][3]);textcolor(black);lowvideo;for r:=3 to 7 do
write(m[7][r]);end else
if z=11
then begin
textcolor(black);for r:=1 to 5 do write(m[8][r]);
textcolor(red);highvideo;
write(m[8][6]);textcolor(black);lowvideo;for r:=7 to 8 do
write(m[8][r]);end else
if z=12
then begin
textcolor(black);for r:=1 to 5 do write(m[9][r]);
textcolor(red);highvideo;
write(m[9][6]);textcolor(black);lowvideo;for R:=7 to 8 do
write(m[9][r]);end else
if z=13
then begin
textcolor(black);for r:=1 to 5 do write(m[10][r]);
textcolor(red);highvideo;
write(m[10][6]);textcolor(black);lowvideo;for r:=7 to 8 do write(m[10][r]);end
else
if z=16
then begin
textcolor(black);for r:=1 to 6 do write(m[13][r]);
textcolor(red);highvideo;
write(m[13][7]);textcolor(black);lowvideo;write(m[13][8]);end else
if z=17 then begin
textcolor(black);for r:=1 to 2 do write(m[14][r]);
textcolor(red);highvideo;
write(m[14][3]);textcolor(black);lowvideo;for r:=4 to 8 do
write(m[14][r]);end else
if z=18
then begin
textcolor(black);for r:=1 to 2 do write(m[15][r]);
textcolor(red);highvideo;
write(m[15][3]);textcolor(black);lowvideo;for r:=4 to 8 do
write(m[15][r]);end else
begin
textcolor(red);highvideo;write(' ',m[z-3][2]);
textcolor(black);lowvideo;
for r:=3 to 8 do write(m[z-3][r]);end;laiks;end;
end;
until false;
end;
{================}
Begin
z:=4;
cur(false);
textmode(co80);
Create(Lst);
Progwin;
ShowEm(Lst);
sakums;
Terminate(Lst);
Window(1,1,80,25);
textattr:=15;
clrscr;
End.



Nav komentāru:
Ierakstīt komentāru