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
And this is the code:
It says that there is General Protection Fault
It always happens like this :(
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
1 2 2 2 5 6 7 7 7 0 1 2 3 4 5 6 7 18 19
And this is the 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.
It says that there is General Protection Fault
It always happens like this :(