Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need help with simple program

pilditupilditu Posts: 2Member
im a total newbie and if someone could help, im very thankful

1)procedure -> read in textfile "F1" (massiv , array of numbers, arbitrary numbers)

2)procedure -> sort the file : a[i]>a[i-1] and a[i]>a[i+1], then write the the result in a columns in a way i a[i-1] a[i] a[i+1], and also to save the result in a new textfile "F2"

thank you a lot!!
sorry for bad english

Comments

  • zibadianzibadian Posts: 6,349Member
    : im a total newbie and if someone could help, im very thankful
    :
    : 1)procedure -> read in textfile "F1" (massiv , array of numbers, arbitrary numbers)
    :
    : 2)procedure -> sort the file : a[i]>a[i-1] and a[i]>a[i+1], then write the the result in a columns in a way i a[i-1] a[i] a[i+1], and also to save the result in a new textfile "F2"
    :
    : thank you a lot!!
    : sorry for bad english
    :
    This is not as simple as it seems. The best way to code this is to use the insertion sort. Here is a very simple and slow implementation of it:
    [code]
    var
    f1, f2, TempFile: text;
    last, current: double;
    DestFilename, Tempfilename, s: string;
    begin
    DestFilename := {destname}; { change destname into the necessary filename }
    TempFilename := DestFilename+'.tmp';
    Assign(f1, {sourcename}); { change sourcename into the necessary filename }
    Reset(f1);
    while not eof(f1) do
    begin
    readln(f1, current);
    { Perform the insertion }
    Assign(f2, DestFilename);
    Reset(f2);
    Assign(TempFile, TempFileName);
    Rewrite(TempFile);
    while not eof(f2) do { Copy all numbers until Last >= Current }
    begin
    readln(f2, Last);
    if Last < Current then { Change this to change the order in which is sorted }
    writeln(TempFile, Last)
    else
    Break;
    end;
    writeln(TempFile, Current); { Insert the current number }
    while not eof(f2) do { Copy all remaining numbers }
    begin
    readln(f2, Last);
    writeln(TempFile, Last)
    end;
    Close(TempFile);
    Close(DestFile);
    s := TempFileName; { Switch from filename for next number }
    TempFileName := DestFileName;
    DestFileName := s;
    end;
    Close(f1);
    end;
    [/code]
    This code will export its results into either DestFilename or TempFilename. You might need to rename the resulting file to the correct name.
  • pilditupilditu Posts: 2Member
    : : im a total newbie and if someone could help, im very thankful
    : :
    : : 1)procedure -> read in textfile "F1" (massiv , array of numbers, arbitrary numbers)
    : :
    : : 2)procedure -> sort the file : a[i]>a[i-1] and a[i]>a[i+1], then write the the result in a columns in a way i a[i-1] a[i] a[i+1], and also to save the result in a new textfile "F2"
    : :
    : : thank you a lot!!
    : : sorry for bad english
    : :
    : This is not as simple as it seems. The best way to code this is to use the insertion sort. Here is a very simple and slow implementation of it:
    : [code]
    : var
    : f1, f2, TempFile: text;
    : last, current: double;
    : DestFilename, Tempfilename, s: string;
    : begin
    : DestFilename := {destname}; { change destname into the necessary filename }
    : TempFilename := DestFilename+'.tmp';
    : Assign(f1, {sourcename}); { change sourcename into the necessary filename }
    : Reset(f1);
    : while not eof(f1) do
    : begin
    : readln(f1, current);
    : { Perform the insertion }
    : Assign(f2, DestFilename);
    : Reset(f2);
    : Assign(TempFile, TempFileName);
    : Rewrite(TempFile);
    : while not eof(f2) do { Copy all numbers until Last >= Current }
    : begin
    : readln(f2, Last);
    : if Last < Current then { Change this to change the order in which is sorted }
    : writeln(TempFile, Last)
    : else
    : Break;
    : end;
    : writeln(TempFile, Current); { Insert the current number }
    : while not eof(f2) do { Copy all remaining numbers }
    : begin
    : readln(f2, Last);
    : writeln(TempFile, Last)
    : end;
    : Close(TempFile);
    : Close(DestFile);
    : s := TempFileName; { Switch from filename for next number }
    : TempFileName := DestFileName;
    : DestFileName := s;
    : end;
    : Close(f1);
    : end;
    : [/code]
    : This code will export its results into either DestFilename or TempFilename. You might need to rename the resulting file to the correct name.
    :
    forgot to mention that the program must be done with procedures
  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2005-5-9 21:50:26[/red][/b][hr]
    : : : im a total newbie and if someone could help, im very thankful
    : : :
    : : : 1)procedure -> read in textfile "F1" (massiv , array of numbers, arbitrary numbers)
    : : :
    : : : 2)procedure -> sort the file : a[i]>a[i-1] and a[i]>a[i+1], then write the the result in a columns in a way i a[i-1] a[i] a[i+1], and also to save the result in a new textfile "F2"
    : : :
    : : : thank you a lot!!
    : : : sorry for bad english
    : : :
    : : This is not as simple as it seems. The best way to code this is to use the insertion sort. Here is a very simple and slow implementation of it:
    : : [code]
    [red]procedure SortFile(Sourcefile, DestFile: string);[/red]
    : : var
    : : f1, f2, TempFile: text;
    : : last, current: double;
    : : DestFilename, Tempfilename, s: string;
    : : begin
    : : DestFilename := DestFile;
    : : TempFilename := DestFilename+'.tmp';
    : : Assign(f1, Sourcefile);
    : : Reset(f1);
    : : while not eof(f1) do
    : : begin
    : : readln(f1, current);
    : : { Perform the insertion }
    : : Assign(f2, DestFilename);
    : : Reset(f2);
    : : Assign(TempFile, TempFileName);
    : : Rewrite(TempFile);
    : : while not eof(f2) do { Copy all numbers until Last >= Current }
    : : begin
    : : readln(f2, Last);
    : : if Last < Current then { Change this to change the order in which is sorted }
    : : writeln(TempFile, Last)
    : : else
    : : Break;
    : : end;
    : : writeln(TempFile, Current); { Insert the current number }
    : : while not eof(f2) do { Copy all remaining numbers }
    : : begin
    : : readln(f2, Last);
    : : writeln(TempFile, Last)
    : : end;
    : : Close(TempFile);
    : : Close(DestFile);
    : : s := TempFileName; { Switch from filename for next number }
    : : TempFileName := DestFileName;
    : : DestFileName := s;
    : : end;
    : : Close(f1);
    : : end;
    : : [/code]
    : : This code will export its results into either DestFilename or TempFilename. You might need to rename the resulting file to the correct name.
    : :
    : forgot to mention that the program must be done with procedures
    :



Sign In or Register to comment.