Авторизация

Логин: Пароль:
Регистрация Забыли свой пароль?

Слияние очереди

Страницы: 1
Слияние очереди, Слить 2 очереди в 1-ну без сортировки а с проверкой вот посмотри мои нароботки
Код
uses
    crt;
type
    fail=file of integer;
    tlist=^list;
    list=record

               inf:integer;
               adr:tlist;
         end;
var
   f1,f2,f3:fail;
   ocher,ocher2,och,oh1,oh:tlist;
   t,c,k,z,i,r,l:integer;
procedure sozd(var och:tlist;x:integer);
var
  tmp:tlist;
begin
  new(tmp);
  tmp^.adr:=och;
  tmp^.inf:=x;
  och:=tmp;
end;
procedure Sort(ocha:tlist);
var
  tmp,tmp1:tlist;
  a:integer;
begin
  new(tmp);
  tmp1:=ocha;
  while tmp1<>nil do
  begin
    tmp:=tmp1^.adr;
    while tmp<>nil do
    begin
      if tmp^.inf<tmp1^.inf then
      begin
        a:=tmp^.inf;
        tmp^.inf:=tmp1^.inf;
        tmp1^.inf:=a
      end;
      tmp:=tmp^.adr
    end;
    tmp1:=tmp1^.adr
  end
end;
procedure zapis_fail( var oh:tlist;  var oh1:tlist);
var
   tmp,tmp1:tlist;
begin
     while (oh<>nil) or (oh1<>nil) do
           begin
                if oh^.inf<oh1^.inf then
                   begin
                        new(tmp);
                        sozd(ocher2,oh1^.inf);
                        tmp:=oh1;
                        oh1:=oh1^.adr;
                        dispose(tmp)
                   end
                else
                    if oh^.inf>oh1^.inf then
                      begin
                        new(tmp1);
                        sozd(ocher2,oh^.inf);
                        tmp1:=oh;
                        oh:=oh^.adr;
                        dispose(tmp1)
                      end;
             if (oh<>nil) and (oh1=nil) then
                while oh<>nil do
                      begin
                           sozd(ocher2,oh^.inf);
                           oh:=oh^.adr;
                      end
             else
                 if (oh=nil) and (oh1<>nil) then
                    while oh1<>nil do
                          begin
                               sozd(ocher2,oh1^.inf);
                               oh1:=oh1^.adr;
                          end
           end;
end;
procedure vivod_fail(var osh:tlist;var f:fail);
begin
rewrite(f);
while osh<>nil do
  begin
    Write(f,osh^.inf);
    osh:=osh^.adr
  end;
close(f);
end;
procedure sozdanie(var ochk:tlist; a:integer);
var
   s:integer;
begin
     for i:= 1 to a do
    begin
         s:=random(1000)-500;
         sozd(ochk,s)
    end;
end;
procedure vivod(var f:fail);
var
   q:integer;
begin
   reset(f);
   while not eof(f) do
         begin
              read(f,q);
              write(q,' ');
         end;
   close(f);
end;
begin
clrscr;
randomize;
assign(f1,'fa.Tol');
assign(f2,'fat.Tol');
assign(f3,'fatik.tol');
writeln('wvedite kol-vo elementov v 1-om faile');
readln(c);
writeln('wvedite kol-vo elementov v 2-om faile');
readln(t);
sozdanie(och,c);
sozdanie(ocher,t);
sozdanie(oh,c);
sozdanie(oh1,t);
Sort(och);
sort(ocher);
Sort(oh);
sort(oh1);
zapis_fail(och,ocher);
vivod_fail(oh,f2);
vivod_fail(oh1,f1);
{zapis_fail(f2,t,r); }
{sort(ocher2);}
vivod_fail(ocher2,f3);
writeln('1-vii fail ');
vivod(f1);
writeln;
writeln('2-oi fail ');
vivod(f2);
writeln;
writeln('rezultat sli9ni9 2-failov ');
vivod(f3);
readkey;
end.

procedure zapis_fail<<< в этой процедуре осущствл само слияние но оно не правильное smile:cry:
Изменено: HaMaChI HaMaChI - 30.10.2010 21:50:28 (не указал нужную процедуру)
Страницы: 1
Читают тему (гостей: 1, пользователей: 0, из них скрытых: 0)
Реклама: