Problem with deleting a node in doubly-linked list. Help me plz) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem with deleting a node in doubly-linked list. Help me plz)

butter_flybutter_fly Posts: 2Member
[color=Purple]Hey :P
Sorry for this silly questions, but I'm only beginner :D
I've written a program which suppose to work, but it doesn't :'(
Anyway. It should create doubly-linked list. And it should compress it.
It should leave only one element from few identical ones.


the data file looks like
[code]
1
2
2
2
5
6
7
7
7
0
1
2
3
4
5
6
7
18
19
[/code]

And this is the code:
[code]program silly;

type
ListType=^ElementType;
ElementType = record
next:ListType;
data:integer;
prev:ListType;
end;
var something,Cursor,TheFirst:ListType;
f:text;
i:integer;
procedure DeleteThoseSillyIdenticalElements();
begin
Cursor:=TheFirst;
while Cursor^.next<>nil do
begin
writeln(Cursor^.data);
if Cursor^.data=Cursor^.next^.data then
begin
if Cursor^.next<>nil then
Cursor^.next^.prev:=Cursor^.prev;
if Cursor^.prev<>nil then
Cursor^.prev^.next:=Cursor^.next;
dispose(Cursor);

end;
Cursor:=Cursor^.next;

end;
end;
begin
assign(f,'a.txt');
reset(f);
new(something);
something^.data:=4;
something^.prev:=nil;
something^.next:=nil;

for i:=1 to 19 do
begin
New(Cursor);
Readln(f,Cursor^.data);
Cursor^.prev:=something;
Cursor^.next:=nil;
something^.next:=Cursor;
if i=1 then TheFirst:=Cursor;
something:=Cursor;
end;
DeleteThoseSillyIdenticalElements();
close(f);
readln();
end.[/code]

It says that there is [b]General Protection Fault[/b]
It always happens like this :(
[/color]
Sign In or Register to comment.