.


:




:

































 

 

 

 


, . vvod (N, L) - , , N - , L - .

, , :

vvod (0, []).

vvod (N, L):-

Readint (X),

N1=N-1,

Vvod (N1, LL),

L = [X|LL].

, .. , , .

: , , .

, .

, . add_in_end (S1, S2, S3) - , , S1 - , , S2 - , ( S2), S3 - .

, , :

add_in_end ([], S, S).

add_in_end ([X|S1], S2, [X| S3]):-

Add_in_end (S1, S2, S3).

: , .

, . , .

, - , . , . . .

: , .

Spisok = [_|S1].

Spisok - , S1 - .

 

, , , .

, , , .. " ".

, .

, : , , . , .

:

  • ;
  • ;
  • , ;
  • ;
  • .

, (. " : ").

 

{ Turbo Pascal, STACK.PAS } Unit Stack; Interface Uses Spisok; Procedure V_Stack(Var Versh: U; X: BT); Procedure Iz_Stack(Var Versh: U; Var X: BT); Function Pust(Versh: U): Boolean; Function V_Vershine(Versh: U): BT; Procedure Ochistka(Var Versh: U); Implementation Procedure V_Stack; Begin V_Nachalo(Versh, X) End; Procedure Iz_Stack; Begin Iz_Nachala(Versh, X) End; Function Pust; Begin Pust:= Versh = Nil End; Function V_Vershine; Begin V_Vershine:= Versh^.Inf End; Procedure Ochistka; Begin Spisok.Ochistka(Versh) End; Begin End.   /* C++, STACK.CPP */ #include "SPIS.CPP" Zveno *V_Stack(Zveno *Versh, BT X) { return V_Nachalo(Versh, X); } Zveno *Iz_Stack(Zveno *Versh) { return Iz_Nachala(Versh); } int SPust(Zveno *Versh) { return!Versh; } BT V_Vershine(Zveno *Versh) { return Versh->Inf; } Zveno *Chistka(Zveno *Versh) { while (!Pust(Versh)) Versh=Iz_Stack(Versh); return Versh; }

 

, .

. , ( ), ( ) . .

. . , ( ) , , ( ), . .

 

{ Turbo Pascal, ST2.PAS } Program St2; Uses Spisok, Stack; Const Znak = ['+', '-', '*', '/']; Var S, S1: String; T: Text; I, N: Byte; X, Y: BT; Code: Integer; NS: U; Begin Write(' : '); ReadLn(S1); Assign(T, S1); ReSet(T); NS:= Nil; While Not Eof(T) Do Begin ReadLn(T, S); I:= 1; While I <= Length(S) Do Begin If S[I] In ['0'..'9'] Then Begin N:= I; While S[I] In ['0'..'9'] Do I:= I + 1; Val(Copy(S, N, I - N), X, Code); V_Stack(NS, X); End Else If S[I] In Znak Then Begin Iz_Stack(NS, X); Iz_Stack(NS, Y); Case S[I] Of '+': X:= X + Y; '-': X:= Y - X; '*': X:= X * Y; '/': X:= Y Div X End; V_Stack(NS, X) End; I:= I + 1 End; Iz_Stack(NS, X); WriteLn(S, ' = ', X); End End.   /* C++, ST2.CPP */ #include "STACK.CPP" #include < string.h > #include < stdio.h > void main(void) { char S[255]; FILE *T; int I; BT X, Y; Zveno *NS; clrscr(); cout << " : "; cin >> S; T=fopen(S, "r"); NS = NULL; while (!feof(T)) { fgets(S, 255, T); I = 0; while (I <= strlen(S)-1) { if (S[I]>='0'&&S[I]<='9') { X=0; while(S[I]>='0'&&S[I]<='9') {X=X*10+(S[I]-'0'); I++;} NS=V_Stack(NS, X); } else if (S[I]=='+'||S[I]=='-'||S[I]=='/'||S[I]=='*') { X=V_Vershine(NS); NS=Iz_Stack(NS); Y=V_Vershine(NS); NS=Iz_Stack(NS); switch (S[I]) { case '+': X += Y; break; case '-': X = Y - X; break; case '*': X *= Y; break; case '/': X = Y / X; break;} NS=V_Stack(NS, X); } I++; } X=V_Vershine(NS); NS=Iz_Stack(NS);

 



<== | ==>
|
:


: 2016-10-07; !; : 236 |


:

:

, , .
==> ...

1800 - | 1696 -


© 2015-2024 lektsii.org - -

: 0.01 .