Link to home
Start Free TrialLog in
Avatar of greenfly
greenfly

asked on

Interpreting codes

Help! Help!, can you please help me I have been learning to program in Borland Pascal for some months now. I wrote the codes for a bookcase program using link list and pointers, I Sent my codes to Expert exchange about 5 weeks ago for help on writing two extra procedures for sorting and deleting books from the list.

The reply was excellent they both work but looking at it I do not really understand clearly how the codes work.
I would be eternally grateful if you could place a line by line comment on what is happening in the two procedures
as I am Practically teaching my self programming with a little help from a friend when he can find the time which is rarely. 100 point is yours see codes below

Many many thanks
--------------------------------------

procedure Display;{display deleted books}
 var
     ch  :char;
 begin
   writeln;
    writeln(space:10,'!!!!--  LIST OF DELETED BOOKS -!!!!: ');
     writeln(space:10,'**************************************');
     if delhead=nil then writeln(space:10,'No Books were deleted')
     else
     Begin
          del:=delhead;
   repeat
   write(space:10,'NAME OF BOOK >: ', del^.Name);
   writeln;
   writeln;
   writeln(space:10,'AUTHOR       >: ', del^.Author);
   writeln;
   writeln(space:10,'PUBLISHER    >: ', del^.Publisher);
   writeln;
   writeln(space:10,'YEAR         >: ',  del^.Year);
   writeln;
   writeln(space:10,'PAGES        >: ', del^.pages);
   writeln;
   writeln(space:10,'SIZE         >: ', del^.size);
   writeln;
   writeln(space:10,'SALE PRICE   >: ', del^.SalePrice);
   writeln;
   writeln(space:10,'Brief Introduction: ', del^.briefdescription);
   writeln;
   write('Do you want to view next book? ');
   read(ch);
   readln;
   del:=del^.next;
   if del=nil then break;
   Until upcase(ch)='N';
   write('End of list of deleted books.');
   readln;
   ClrScr;
     end;
     writeln;
end;

------------------------------------
{Procedure for sorting books in ascending order}

procedure sort;
var node1,node2 : link;
    m,n : integer;
procedure swap(n1,n2 : link);
var temp: booknode;
begin

       temp:=n1^;

       n1^.Pages:=n2^.Pages;
       n1^.Year:=n2^.Year;
       n1^.Author:=n2^.Author;
       n1^.Publisher:=n2^.Publisher;
       n1^.Name:=n2^.Name;
       n1^.SalePrice:=n2^.SalePrice;
       n1^.Size:=n2^.Size;
       n1^.BriefDescription:=n2^.BriefDescription;

       n2^.Pages:=temp.Pages;
       n2^.Year:=temp.Year;
       n2^.Author:=temp.Author;
       n2^.Publisher:=temp.Publisher;
       n2^.Name:=temp.Name;
       n2^.SalePrice:=temp.SalePrice;
       n2^.Size:=temp.Size;
       n2^.BriefDescription:=temp.BriefDescription;

end;
begin
      writeln;
      write('Sorting the list taking yearofbook as primary key.');
      node1:=head;

      for m:=1 to count-1 do
      begin
           node2:=node1^.next;
           for n:=m+1 to count do
           begin
                if node1^.year > node2^.year then
                begin
                      swap(node1,node2);
                end;
                node2:=node2^.next;
                write('.');
           end;
           node1:=node1^.next;
      end;
      writeln;
      writeln('Sorting complete.');
      readln;
      clrscr;
end;


ASKER CERTIFIED SOLUTION
Avatar of guyss
guyss

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial