Ok, this time I've actually tired to do this problem before asking for assistence, but anyway the problem is to create a linked list with 5-7 records. Your program will take an input input value. It will then search for a record, which has the same value as the input value. If the search is successful, it will insert the matching record at the fron of the list. If not, it will output the original list. So far I have this:
program searchrecord;
type
ptr = ^node;
node = record
number: integer;
next: ptr;
end;
var betw, last, extra, head, prev, curr, point, next: ptr;
i, data, moveDistance: integer;
done: boolean;
x: integer;
begin
{----- start of list creation--------}
head := nil;
prev := nil;
for i := 1 to 5 do
begin
if head = nil then
begin
new (head);
writeln('Enter #');
readln(head^.number);
last := head;
end
else
begin
new (extra);
writeln('Enter #');
readln(extra^.number);
last^.next := extra;
last := extra;
end;
end;
last^.next := nil;
{-----------end of list creation-------------}
{----------start of list search--------------}
curr := head;
prev := nil;
writeln('Enter data to be moved');
readln(data);
done := false;
while(done = false) and (curr <> nil) do
begin
if data <> curr^.number then
begin
prev := curr;
curr:= curr^.next;
end
else done:= true;
end;
{----------------end of list search--------------}
{-------start of list print--------------}
point:= head;
while (point <> nil) do
begin
writeln(point^.number);
point := point^.next;
end;
{-------end of list print----------------}
end.
Now what I trying to do is put data in for those records, and trying to search for the input value and move that matching record to the front of the list. Thanks.
program searchrecord;
type
ptr = ^node;
node = record
number: integer;
next: ptr;
end;
var betw, last, extra, head, prev, curr, point, next: ptr;
i, data, moveDistance: integer;
done: boolean;
x: integer;
begin
{----- start of list creation--------}
head := nil;
prev := nil;
for i := 1 to 5 do
begin
if head = nil then
begin
new (head);
writeln('Enter #');
readln(head^.number);
last := head;
end
else
begin
new (extra);
writeln('Enter #');
readln(extra^.number);
last^.next := extra;
last := extra;
end;
end;
last^.next := nil;
{-----------end of list creation-------------}
{----------start of list search--------------}
curr := head;
prev := nil;
writeln('Enter data to be moved');
readln(data);
done := false;
while(done = false) and (curr <> nil) do
begin
if data <> curr^.number then
begin
prev := curr;
curr:= curr^.next;
end
else done:= true;
end;
{----------------end of list search--------------}
{-------start of list print--------------}
point:= head;
while (point <> nil) do
begin
writeln(point^.number);
point := point^.next;
end;
{-------end of list print----------------}
end.
Now what I trying to do is put data in for those records, and trying to search for the input value and move that matching record to the front of the list. Thanks.