:





.NET Queue




:
  1. -
  2. III
  3. t- ( ).
  4. ³ 11 , ̲Ͳ ² , IJ

(queue) - , " , " (frst n, frst out - FFO). , , . , , . , -, .

 

2.1 -

 

:

- (nt);

- (Destroy);

- (nsert);

- (Remove);

- (Head);

- (Tal);

- (sempty);

- (sfull)

 

.NET Queue

.NET Queue System.Collecton Queue<T> System.Collectons.Generc. , , , , Object. Queue<T> ,

Queue System.Collectons Queue<T> System.Collectons.Generc.

Queue :

1. Enqueue() - ;

2. Dequeue() - .

. Queue :

1. Contans() - ' ;

2. Count - , ;

3. Peek() - , .

 

:

usng System;

usng System.Collectons.Generc;

usng System.Lnq;

usng System.Text;

usng System.Collectons;

 

namespace Query2

{

class Program

{

statc vod Man(strng[] args)

{

Queue q = new Queue();

q.Enqueue(2); //



q.Enqueue(3); //

q.Enqueue(5); // '

// : 5 3 2

Console.Wrtelne(" " + q.Count + "

'"); // 3

Console.Wrtelne(" : " + q.Peek());

// 2

Console.Wrtelne Console.Wrtelne(((nt)q.Dequeue() +

(nt)q.Dequeue()) * (nt)q.Dequeue());

//2+3*5

Console.Readkey(true);

}

}

}

 

Queue. ϳ 3 . ' nt. . , ' . , . , . - . nt ', ' object , .

', , , "" .

, ' . .. :



q.Enqueue(""); //

q.Enqueue(3); //

q.Enqueue(4); //

q.Enqueue(5); // ',

 

"" , .

 

2.1 - Queue Queue<T>

Enqueue() .
Dequeue ()     . Dequeue (), nvaldoperatonexcepton.
Peek() , .
Count .
TrimExcess()     . Dequeue () , . , TrimExcess().
Contains()   true,
() ()
ToArray()   , .

, Queue.

 

1. .

usng System;

usng System.Collectons.Generc;

usng System.Lnq;

usng System.Text;

 

namespace Consoleapplcaton1

{

class Program

{

statc vod Man(strng[] args)

{

Queue<nt> ffo = new Queue<nt>();

ffo.Enqueue(1);



ffo.Enqueue(2);

ffo.Enqueue(3);

ffo.Enqueue(4);

ffo.Enqueue(5);

Console.Wrtelne(" {0}", ffo.Peek());

Console.Wrtelne(" {0}", ffo.Peek());

 

//

for (nt = 0; < 5; ++)

{

Console.Wrtelne(" {0}", ffo.Count);

Console.Wrtelne(" {0}",ffo.Dequeue());

}

Console.Readkey(true);

}

}

}

 

2. .

usng System;

usng System.Collectons.Generc;

 

namespace Consoleapplcaton1

{

class Program

{

statc vod Man()

{

Queue qe = new Queue<nt>();

Random ran = new Random();

for (nt = 0; < 10; ++)

qe.Enqueue(ran.Next(1, 10));

 

Console.Wrtelne(": \n");

foreach (nt n qe)

Console. Wrte( + "\t");

Console.Readlne();

}

}

}

 

3. .

usng System;

usng System.Collectons;

publc class Samplesqueue {

 

publc statc vod Man() {

 

// Creates and ntalzes a new Queue.

Queue myq = new Queue();

myq.Enqueue("Hello");

myq.Enqueue("World");

myq.Enqueue("!");

 

// Dsplays the propertes and values of the Queue.

Console.Wrtelne( "myq" );

Console.Wrtelne( "\tcount: {0}", myq.Count );

Console.Wrte( "\tvalues:" );

Prntvalues( myq );

}

 

publc statc vod Prntvalues( enumerable mycollecton ) {

foreach ( Object obj n mycollecton )

Console.Wrte( " {0}", obj );

Console.Readkey();

 

}

}


: 2015-09-15; : 10;







lektsii.com - . - 2014-2021 . (0.041 .)