Post my C homework coming out of the experiment two stacks and queues - 2

xiaoxiao2021-03-06  40

Experiment 2 stack and queue

First, the experimental purpose

1. Familiar with the order and chain storage structure of stacks and queues

2. Master the basic operation of the stack and queue

3. Ability to use the basic operations of the stack and queue to complete the operation of the stack and queue application

Second, the experiment content

2. Suppose the elements of the loop queue are stored in array sequ [m], and the variables REAR and Quelen are set to indicate the position of the tail elements in the loop queue, respectively. Number of elements. Writing an algorithm for implementing the entry and out of the team in this loop queue. Tip: Team conditions: sq-> queelen == 0; Team full condition: sq-> queelen == m. (Folder: exercise 10_9)

/ * Structure type definition of cyclic queue. H * /

#define m 5

TypedEf int Dattype;

Typedef struct

{Datatype SEQU [M];

INT REAR, Quelen;

} qu;

/ * Cycle queue is included in the team's main program .cpp * /

#include

#include

#include "Cycle queue definition .h"

#include "blank team .h"

#include "into the team .h"

#include "out of the team .h"

int main ()

{Qu * sq;

DataType X, * P;

Int key;

/ * sq = new qu; * /

SQ = (QU *) Malloc (SIZEOF (QU));

Setnull (SQ);

DO

{/*Cout<<"1.enter queue 2.delete queue -1.quit: ";

CIN >> KEY;

* /

PUTS ("1.enter Queue 2.delete Queue -1.quit:");

Scanf ("% d", & key);

Switch (key)

{Case 1: / * cout << "Enter the data:"; cin >> x; * /

PUTS ("Enter the Data:"); scanf ("% d", & x);

ENQUEUE (SQ, X); BREAK;

Case 2: P = Dequeue (SQ);

IF (p! = null) / * cout << * p << endl; * /

Printf ("% d / n", * p);

Break;

Case -1: exit (0);

}

WHILE (1);

Return 0;

}

/ * This program enters non-numeric when an error * /

/ * Set the air team. H * /

Void setnull (QU * SQ)

{SQ-> REAR = M-1;

SQ-> queelen = 0;

}

Void Enqueue (Qu * SQ, DataType X)

{

IF (sq-> queelen == m)

{

Printf ("Team Full, Failure ./n");

Return;

}

SQ-> Rear = (SQ-> REAR 1)% M;

SQ-> SEQU [SQ-> REAR] = X;

SQ-> queelen ;

Return;

}

DataType * Dequeue (QU * SQ)

{

DataType * x;

x = (Datatype *) Malloc (SizeOf (Datatype));

IF (sq-> queelen == 0)

{

Printf ("Team, the queue failed ./n" ";return 0;

}

* x = sq-> sequ [(SQ-> Rear-Sq-> Quelen 1 M)% M];

SQ-> queelen--;

Return X;

}

转载请注明原文地址:https://www.9cbs.com/read-77394.html

New Post(0)