.


:




:

































 

 

 

 


, . : 2, 10 20 int, short char, - int, float char.

 

. ()
  ()
 
  ( )
 
  ( )
  ( )
 
 
  ( )
 
  ( )
 
 
 
 
 
  ( )
 
  ()
 

 

. .

 

.

0 ai , ai< 0, ; . 1 . .

: , . (0 1, 1 2, ..) , , . (right). , right. . (left). left right ..

.

d , , d. , . d: 1, 3, 7, 15, 31, ,..

dk=(dk-1-1)/2

d . , , , .

0 1, 1 2, .. i>ai+1, ai+1 : , , . , , .

( )

, , . (, ), . . , x i<= x, aj>=x. x . , , , . , . left right x: i j, i = left; j=right. , ai>= x, , aj<= x. . , i > j.

, m (m <= n). .

0, 1, , i-1 i, ai+1, ,an-1. i ( i =1) i . i =2,3,,n-1. i i , i-1, ai-2 .. j<=ai .

, , ai , ai , , .

. , 0. . , , . , . , , , . .

(0 1, 2 3 ..) b. b , , ; b .. .

, . : c ( ), a b ( ). , b ( ). , . , , b ( ). . , b ( ). a b ( ). a b , a b , .

n .

: c ( ), a, b d ( ). , b. , , b. d. c d , a b .. .

n .

, , . a b. . a b. i- a b (i=1,2,3,) , : a. .

n .

a, b, d. . a b. i- a b (i=1,2,3,) d. d a b .. .

n .

, x. . , , , , .

, x. , al ar,

m=l+(r-l)*(x-al)/(ar-al)

, (m), , , .

 

1. :

template <class t>

void change (t a, t b)

{ t c;

c=a; a=b; b=c; }

 

2.

#include <iostream>

#include <conio>

template <class T>

T maximum(T value1, T value2, T value3)

{ T max=value1;

if (value2>max) max=value2;

if (value3>max) max=value3;

return max;}

void main(){

int i1, i2, i3;

cout<<" : ";

cin>>i1>>i2>>i3;

cout<<" : "<<maximum(i1, i2, i3);

double d1, d2, d3;

cout<<" double: ";

cin>>d1>>d2>>d3;

cout<<" : "<<maximum(d1, d2, d3);

char ch1, ch2, ch3;

cout<<" : ";

cin>>ch1>>ch2>>ch3;

cout<<" : "<<maximum(ch1, ch2, ch3);

getch();}

 

3. 2, .

1.

#include <iostream>

#include <conio>

template <class Tree>

Tree maximum(Tree M, Tree MM)

{ Tree max=MM;

if (M>max) max=M;

return max;}

void main(){

int i;

int Vremi,MI[10];

cout<<"*** Int *** \n";

for (i=0; i<=10; i++){

cin>>MI[i];

if (i==0) Vremi=MI[i];

Vremi=maximum(MI[i],Vremi);}

cout<<"Max: "<<Vremi<<"\n";

double Vremd,MD[10];

cout<<"*** Double *** \n";

for (i=0; i<=10; i++){

cin>>MD[i];

if (i==0) Vremd=MD[i];

Vremd=maximum(MD[i],Vremd);}

cout<<"Max: "<<Vremd<<"\n";

char VremCh,MCh[10];

cout<<"*** Char *** \n";

for (i=0; i<=10; i++){

cin>>MCh[i];

if (i==0) VremCh=MCh[i];

VremCh=maximum(MCh[10],VremCh);}

cout<<"Max: "<<Vremd<<"\n";

getch();}

2.

#include <iostream>

#include <conio>

template <class Tree>

Tree maximum(const Tree *array)

{ Tree max=array[0];

for (int i=0; i<=10; i++)

if (array[i]>max) max=array[i];

return max;}

void main(){

int i;

int MI[10];

cout<<"*** Int *** \n";

for (i=0; i<=10; i++) cin>>MI[i];

cout<<"Max: "<<maximum(MI)<<"\n";

double MD[10];

cout<<"*** Double *** \n";

for (i=0; i<=10; i++) cin>>MD[i];

cout<<"Max: "<<maximum(MD)<<"\n";

char MCh[10];

cout<<"*** Char *** \n";

for (i=0; i<=10; i++) cin>>MCh[i];

cout<<"Max: "<<maximum(MCh)<<"\n";

getch();}

6.

, , . . , . . 1 -3.

 

1

, n , , , (.1), (.11), , 1, 11
, n , , (. 12), (. 2, 18), 2, 12, 18
, , n , , , , 3, 13
, n , , , , , 4,14, 15
, , , , , , 5, 16
, (. 17), (.6), n , , (. 6), (. 17), , 6, 17
, , n , , , , ,  
, n , , , , , , ,  
, , , , , , 9, 19
, , , , , , . 10, 20

 

2

1, 3, 4, 5, 19, 20
13, 15
9, 10
 
 
6, 7, 8, 11, 14, 16, 17
 

 

3

9 , 25 , 1, 2, 3, 4, 6,
20 , - 20 , 7, 8, 11, 12, 14, 17
, 20, - 5, 16
13, 15, 18
, 20 9, 19
() , () 25 10, 20

 

.

 

#include <iostream.h>

#include <conio.h>

#include <string.h>

#include <stdlib.h>

struct tlist //

{

char info[10]; //

tlist *next; //

};

typedef tlist *plist; // " "

void add(plist &list, char s[])

{

plist node; //

node=new tlist; //

strcpy(node->info,s); //

node->next=list->next;

list->next=node; //

}

void main(void)

{

plist list; //

char s[10];

//

list=new tlist;

list->next=list;

//

cout<<"s? ";

cin>>s;

add(list,s);

cout<< list->next->info; //

getch();

}



<== | ==>
. . |
:


: 2016-12-06; !; : 374 |


:

:

, ,
==> ...

1737 - | 1664 -


© 2015-2024 lektsii.org - -

: 0.08 .