Created
February 11, 2017 05:06
-
-
Save xypnox/e38a5b5f555dc58b38dffb7e0064f44d to your computer and use it in GitHub Desktop.
question practical
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* AISSCE 2017 | |
* Set 2 | |
* | |
* This Program stores data of players using a class based queue | |
* The Player can be inserted at the rear | |
* and the deletion occurs at the front | |
* | |
* It uses a first come first serve method | |
*/ | |
#include <iostream.h> | |
#include <conio.h> | |
#include <stdio.h> | |
struct PLAYER { | |
// this is a self referenced structure to store data for players | |
int Pno; | |
char Pname[80]; | |
char game[80]; | |
PLAYER *next; // The link to the next player | |
}; | |
class q{ | |
// This class maintains the queue using pointers front and rear | |
PLAYER *front; | |
PLAYER *rear; | |
public: | |
q() { | |
front = rear = NULL; // Initial values of front and rear | |
} | |
void Qinsert(); //function for insertion at the rear | |
void Qdelete(); //function for detelion at the front | |
void traverse(); // funtion for displaying the Queue | |
}; | |
void q::Qinsert() { | |
// Definition of Qinsert | |
PLAYER *nn = new PLAYER; | |
cout << endl << "Enter Player Number : "; | |
cin >> nn->Pno; | |
cout << "Enter Player Name : "; | |
gets(nn->Pname); | |
cout << "Enter Player Game : "; | |
gets(nn->game); | |
nn->next = NULL; | |
if (rear == NULL) { | |
front = rear = nn; | |
} else { | |
rear->next = nn; | |
rear = nn; | |
} | |
} | |
void q::Qdelete() { | |
// definition of Qdelete | |
if (front == NULL) { | |
cout << "ERROR: Empty Queue"; | |
} else if (front == rear) { | |
front = rear = NULL; | |
} else { | |
PLAYER *t = front; | |
front = front->next; | |
t = NULL; | |
delete t; | |
cout << endl << "Deleted!!"<<endl; | |
} | |
} | |
void q::traverse() { | |
// definition of Qtraverse | |
if(front == NULL) { | |
cout << "Empty!!"; | |
} else { | |
cout << endl << "The Queue is : " << endl; | |
PLAYER *temp = front; | |
while (temp != NULL) { | |
cout << "\t" << temp->Pno << "\t" << temp->Pname << "\t" << temp->game << endl; | |
temp = temp->next; | |
} | |
} | |
} | |
void main() { | |
clrscr(); | |
q plrs; | |
// Insertion of three elements | |
plrs.Qinsert(); | |
plrs.traverse(); | |
plrs.Qinsert(); | |
plrs.traverse(); | |
plrs.Qinsert(); | |
plrs.traverse(); | |
// Deletion | |
plrs.Qdelete(); | |
plrs.traverse(); | |
// Insertion of an element | |
plrs.Qinsert(); | |
plrs.traverse(); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment