تبديل برنامه پاسكال به c++

oranoos_mta

New Member
من اين سورس را به زبان پاسكال گير آوردم ولي تو تبديل كردن كلاس و procedure به زبان cpp مشكل دارم خواهشن كمك كنيد
کد:
program p11;
uses crt;
type
    pnode=^node;
    node=record
                data:integer;
                llink:pnode;
                rlink:pnode;
                end;
const
     head:pnode=nil;
var
   temp,now:pnode;
   i,y:integer;
procedure add(data:integer);
begin
     new(temp);
     temp^.data:=data;
     temp^.rlink:=nil;
     temp^.llink:=nil;
     if head^.rlink=head then
        begin
             temp^.rlink:=head;
             temp^.llink:=head;
             head^.rlink:=temp;
             head^.llink:=temp;
        end
     else
         begin
              temp^.rlink:=head;
              temp^.llink:=head^.llink;
              head^.llink^.rlink:=temp;
              head^.llink:=temp;
         end;
end;

function del(data:integer):boolean;
         begin
              now:=head^.rlink;
              del:=false;
                      repeat
                            if now^.data=data then
                               begin
                                            now^.llink^.rlink:=now^.rlink;
                                            now^.rlink^.llink:=now^.llink;
                                            dispose(now);
                                            del:=true;
                                            break;
                                       end
                                    else
                                        now:=now^.rlink;
                               until now=head^.rlink;
         end;
procedure printlist;
begin
     now:=head^.rlink;
     if now<>head then
     repeat
          writeln(now^.data);
          now:=now^.rlink;
     until now=head;
end;
procedure printreverselist;
begin
     now:=head^.llink;
     if now<>head then
     repeat
           writeln(now^.data);
           now:=now^.llink;
     until now=head;
end;
procedure disposelist;
begin
     now:=head^.rlink;
     if now<>head then
          repeat
                temp:=now^.rlink;
                dispose(now);
                now:=temp;
          until temp=head;
     dispose(head);
end;
procedure mainmenu;
begin
     while true do
     begin
          clrscr;
          writeln('1:Add  2:del   3:print 4:reverse print 5:exit':60);
          write('         plesae enter n number : ');
          readln(i);
          case i of
          1: begin
             clrscr;
             writeln('add':40);
             write('           enter the number : ');
             readln(y);
             add(y)
             end;
          2: begin
             clrscr;
             writeln('del':40);
             write('           enter the number : ');
             readln(y);
             if not(del(y)) then
             begin
                  write('       number is not avilabel !');
                  readkey;
             end;
             end;
          3: begin
             clrscr;
             writeln('print':40);
             printlist;
             write('           any key for continue : ');
             readkey;
             end;
          4: begin
             clrscr;
             writeln('reverse print':40);
             printreverselist;
             write('          press any key...');
             readkey;
             end;
          5: break
          end;
     end;
end;
begin
     new(head);
     head^.llink:=head;
     head^.rlink:=head;
     mainmenu;
     disposelist;
end.
 

جدیدترین ارسال ها

بالا