.


:




:

































 

 

 

 


.




2

 

.

 

, (, , ) . , " ". :

( ) . , ;

. , . , , , .

. , , , .

- , () , , :

struct __

{

_; /* */

struct __ * ;

};

: ( D), , ( L).

, , : " , , ".

. 1 , . : beg - ; end - , ; rex - "" .

 
 

 

 


1.

. . .

#include <iostream>

#include <conio.h>

using namespace std;

// " "

struct cell

{ char sign[10];

int weight;

cell *pc;

};

void main()

{ cell *rex; //

cell *beg = NULL; //

cell *end = NULL; //

cout << "Input value struct\n"; //

//

do

{ //

cell *rex = new cell;

//

cout << "sign = ";

cin >> rex->sign;

cout << "weight = ";

cin >> rex->weight;

if(rex->weight == 0)

{ delete [] rex;

break; //

}

//

if(beg == NULL && end == NULL)

beg = rex; // -

else

end->pc = rex; //

end = rex;

end->pc = NULL;

}

while(1); //

//

cout << "\nContent of list"; //

rex = beg;

while(rex!= NULL)

{ cout << "\nsign = " << rex->sign

<< "\tweight = " << rex->weight;

rex = rex->pc;

}

getch();

}

 

:

:

Sign=sigma

weight=16

Sign=omega

weight=44

Sign=alfa

weight=0

:

Sign=sigma weight=16

Sign=omega weight=44

, weight .

, .. , . , int weight .

. -beg, end - .

(struct cell *) struct cell. malloc() void *, rex struct cell *. , - void * .

.

 

.

, , , 2. D, L.

 
 

 


2

. , . .

() () . , . .

, .

:

struct cell * input (void);

, . , . , weight. , struct cell * , input(), . , .. struct cell * .

input(), , .

1. input() , .

2. () , .

3. weight, , . , , .

4. weight , input() NULL.

5. () , .

6. :

,

:

( )

-

.

, ; .

input() . struct cell . , . free(p) return NULL;. ( struct cell * ) input(). . input() , input() NULL, , .

:

void output (struct cell * );

( ), - struct cell * . NULL - , . . , , output() ->. . - " !" , .

:

/* " ";*/

#include <iostream>

#include <conio.h>

using namespace std;

// " "

struct cell

{ char sign[10];

int weight;

cell *pc;

};

//

cell *f_input(void)

{ //

cell *p = new cell;

//

cout << "sign = ";

cin >> p->sign;

cout << "weight = ";

cin >> p->weight;

if(p->weight == 0)

{ delete [] p;

return NULL;

}

p->pc = f_input(); //

return p;

}

//

void f_output(cell *p)

{ if(p == NULL)

{ cout << "\nEnd of listing!"; //

return;

}

cout << "\nsign = " << p->sign

<< "\tweight = " << p->weight;

f_output(p->pc); //

}

void main()

{ cell *beg = NULL; //

cout << "Input value struct\n"; //

beg = f_input(); //

cout << "\nContent of list"; //

f_output(beg);

 

getch();

}

:

:

Sign=Zoro

weight=l938

Sign=Zodiac

weight=1812

Sign=0

weight=0

:

Sign==Zoro weight=1938

Sign=Zodiac weight=1812

!

 

 

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

       
   
 
 
 

 

 


:

struct __

{

_; /* */

struct __ * ;

struct __ * ;

};

. , , : beg , end , rex . .

#include <iostream>

#include <conio.h>

using namespace std;

// " "

struct cell2

{ char sign[10];

int weight;

cell2 *pc1;

cell2 *pc2;

};

void main()

{ cell2 *rex; //

cell2 *beg = NULL; //

cell2 *end = NULL; //

cout << "Input value struct\n"; //

//

do

{ //

cell2 *rex = new cell2;

//

cout << "sign = ";

cin >> rex->sign;

cout << "weight = ";

cin >> rex->weight;

if(rex->weight == 0)

{ delete [] rex;

break; //

}

//

if(beg == NULL && end == NULL)

{ beg = rex; // -

beg->pc1 = NULL;

}

else

{ end->pc2 = rex; //

rex->pc1 = end;

}

end = rex;

end->pc2 = NULL;

}

while(1); //

//

cout << "\nContent of list"; //

rex = beg;

while(rex!= NULL)

{ cout << "\nsign = " << rex->sign

<< "\tweight = " << rex->weight;

rex = rex->pc2;

}

getch();

}

 

, struct cell struct cell2, . .

 





:


: 2016-12-18; !; : 949 |


:

:

.
==> ...

1612 - | 1463 -


© 2015-2024 lektsii.org - -

: 0.084 .