help convert from pascal to c++



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  Program test;
Const  nmax=50;
Type
      Pemat = ^emat;
      emat=record
           col:integer;
           val:real;
           next:pemat;
       end;
    holemat =array [1..nmax] of pemat;
Procedure  insert(var  ph:pemat;   j:integer;  x:real);
Var
       p,prev: pemat;
Begin
       if  ph=nil  then   
           begin
               new(ph);
               ph^.col:=j;
               ph^.val:=x;
               ph^.next:=nil;
           end
        else
           begin
                if  ph^.col > j  then   
                    begin
                         p:=ph;
                         new(ph);
                         ph^.col:=j;
                         ph^.val:=x;
                         ph^.next:=nil;
                    end
            else     
                 begin
                       p:=ph;     prev:=nil(أو  ph);
                       while  (p<>nil) and(p^.col>j)  do
                            begin
                                 prev:=p;
                                 p:=p^.next;
                             end;
                        new(prev^.next);
                        prev^.next^.col:=j;
                        prev^.next^.val:=x;
                        prev^.next^.next:=p;
                 end;
end;  {procedure}
--------
Procedure  readmat(var  n,m:integer;  var a:holemat;);
Var
      i,j:integer;
Begin
      writeln('enter  the two  dimention  mat');
      readln(n,m);
      for  k:=1 to  nmax  do
          a[k]:=nil;
      repeat
          writeln('enter Line , coloume,  value');
          readln(i ,j ,x);
          insert(a[i] ,j  ,x);
       until  (i=0) and (j=0) and (x=0); 
 End;{procedure}
-------
Procedure  writehmat (n ,m : integer; a:holemat);
var   p:pemat;
begin
    for  k:=1 to n do
       begin
            p:=a[k];
            while  p<>  nil  do
                begin
                       writeln('a[',k,',p^.col',']=',p^,val);
                       p:=p^.next;
                end;
  end;
-----------------------------
Function  Max_mat(n,m:integer;  a:holemat): real;
Var
      p:pemat;
      i:integer;
      found:Boolean;
Begin
      i:=1;
      found:=false;
      while (i=<n) and (not found)  do
         begin
             if a[i]<>nil  then
                begin
                      found:=true;
                      max:=a[i]^.val;
                 end;
              i:=i+1;
         end;
      if not(found) then
          writeln(  max:=0)
      else
          begin
               for  i-1  to n  do
                    begin
                        p:=a[i];
                        while p<> nil  do
                              begin
                                   if  p^.val>max  then
                                        max:=p^.va;
                                    p:=p^.next;
                               end;
                     end;
         max_mat:=max;
end;    
------------------
Procedure  append (var  ph,pt:pemat;  j:integer;  x:real);
Var
       P:pemat;
Begin
     if  ph=nil  then
           begin
               new((ph);
               pt:=ph;
               ph^.val:=x;
               ph^.next:=nil;
           end
    else
         begin
              new(pt^.next);
              pt:=pt^.next;
              pt^.col:=j;
              pt^.next:=nil;
         end;
end; 
-------------
Procedure  add_two_mat (n ,m:integer;  a,b:holemat;  var c:holemat);
Var
     p ,q :pemat;
      i: integer;
Begin
    for i:=1  to  n  do
        begin
            c[i]:=nil;   current:=nil;
            p:=a[i];     q:=q[i] ;
            while  (p<>nil) and (q<>nil) do
                  begin
                        if p^.col<q^.col  then
                             begin
                                     append(c[i],current,p^.col,p^.val);
                                     p:=p^.next;
                              end
                        else
                              if  q^.col>p^.col  then
                                   begin
                                        append(c[i],cuurent,q^.col,q^.val);
                                        q:=q^.next;
                                    end
                               else
                                     begin
                                         append(c[i],q^.col,q^.val+p^.val);
                                         p:=p^.next;
                                         q:=q^.next;
                                      end;
                     end;
            while  p<>nil  do
                  begin
                        append(c[i],current,p^.col,p^.val);
                        p:=p^.next;
                  end;
            while  q<>nil  do
                 begin
                      append(c[i],current,q^.col,q^.val);
                      q:=q^.next;
                 end;
         end;{for}
end;

               
Topic archived. No new replies allowed.