Created
November 29, 2012 05:31
-
-
Save 4lex1v/4167007 to your computer and use it in GitHub Desktop.
LinkedList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit LinkedList; | |
interface | |
type | |
pt =^ elem; | |
elem = record | |
entry: string; | |
count: integer; | |
next: pt; | |
end; | |
llist = pt; | |
procedure put(list: llist; val: string); | |
function get(ll: llist; index: integer): string; | |
implementation | |
function get(ll: llist; index: integer): string; | |
var | |
res, p : llist; | |
begin | |
if ll = nil then | |
get := 'The List is Empty' | |
else | |
p := ll; | |
res := nil; | |
while p^.next <> nil do begin | |
if p^.count = index then | |
res := p; | |
p := p^.next; | |
end; | |
if res = nil then | |
get := 'Not Found' | |
else | |
get := res^.entry; | |
end; | |
procedure put(list: llist; val: string); | |
var | |
q, p : llist; | |
counter : integer; | |
begin | |
new(q); | |
q^.entry := val; | |
q^.count := 0; | |
q^.next := nil; | |
if list = nil then | |
list := q | |
else | |
begin | |
p := list; | |
counter := 0; | |
while p^.next <> nil do begin | |
counter := counter + 1; | |
p := p^.next; | |
end; | |
q^.count := counter; | |
p^.next := q; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment