var
name:array[1..10] of string;
age:arrat[1..10] of integer;
email:array[1..10] of string;
begin
name[1]:='Kim';
........
end.
for crt the part of array and make the program more easy to understand,
a record delcaraction used:
type
"record name"= record
variable:indentify/types;
.......
end;{end is used to end record;}
a sample of the above record are here:
sample 1.
type
information:record
email,name:String
age:integer;
end;
var
FriendInfo:array[1..10] of information;
begin
friendinfo[1].name:='Kim wong'; {prestore function}
friendinfo[1].age:=16;
friendinfo[1].email:='autokim@hkstar.com';
writeln('friend information 1',friendinfo[1].name);{read ,write
function}
allright ,go for another :data structure.
the different organized forms of data/array are called data
structures.
here is two kind of data structure
A.list:it refers to the organization of data items in a linear
manner.
here is a sample of list:
var
N:array[1..10] of ineger;
begin
N[1]:=1;
N[2]:=3;
N[3]:=2;
N[4]:=4;
..........
end.
or ,replace the Number by string,we can get a string list.....
B.linked list,
the most useful and hardest data structure:
linked list ,is a list of nodes and each node contains
the
data together with a pointer to the next node,
There is an last node have null pointer whcih does bot
point to any node to indicate the end of list,
there is also a head does which link to the first data.
the list are like this : ( ) data inside a node
------> a link
process 1
______1___________2____________3__________4
head -------> (Kim) ---------> (Mary) --------> (sam) -------->
null pointer [represent end]
if data mary is deleted then the link become:
process 2
1
4
head -------> (KIM) (mary)
(sam) ----------> null pointer
|
^
|_________3______ |
link 3 deleted .....
here is a sample of linked list:
sample 2:
var
name:array [1..6] of string;{maxium 6 data}
link:array[1..6] of integer; {simply ,array of record may be
used}
endlink:integer;
i:integer;{counter}
input:string;
found:integer;
begin
name[1]:='kim';
link[1]:=2;{primary linked to the end : "2"}
name[2]:='mary';
link[2]:=3;{another link added,so the end become :"3" and "end
link:= end link+1"}
name[3]:='sam';
link[3]:=4;
endlink:=4;
{add a new data:}
writeln('add a new data here:');
readln(input)
name[endlink]:=input;
link:=endlink+1;
endlink:=endlink+1;
{delete a data, searching used}
writeln('please enter a data to delete');
readln(input);
for i:= 1 to endlink-2; do
begin
if name[i]=input then
found:=i;
end;
if found>0 then
link[found]:=link[found]+1;
if name[endlink]=input-1 then
endlink:=endlink-1;
end.
<< Previous