Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -------------------------- myNode.h ---------------------------*/
- #ifndef myNode_h
- #define myNode_h
- #include <iostream>
- class Node {
- private:
- char *clientName;
- double clientState;
- public:
- Node *next;
- Node();
- Node(char *, int);
- void setName(const char *);
- void setState(const double);
- char* getName() const;
- double getState() const;
- ~Node();
- };
- #endif
- /* -------------------------- myQueue.h ---------------------------*/
- #include <iostream>
- using namespace std;
- #ifndef myQueue_h
- #define myQueue_h
- class Queue {
- friend void printQ();
- private :
- Node* head;
- Node* tail;
- public:
- Queue();
- void insertNode(Node);
- Node *getLast();
- Node *peek();
- bool isEmpty();
- };
- void printQ(Queue &Q)
- {
- Node *location= Q.head;
- if (!location) { cout <<"There are no clients!"<<endl; }
- while (location)
- {
- // cout << "Client Name: "<< location->clientName ;
- // cout << " Client State: "<<location->clientState << endl ;
- // location=location->next;
- }
- }
- #endif
- /* -------------------------- myNode.cpp ---------------------------*/
- #include <iostream>
- #include "myNode.h"
- #include <cstring>
- using namespace std;
- Node :: Node()
- {
- this->clientName = NULL;
- this->clientState=0;
- this->next=NULL;
- }
- Node::Node(char *name, int state)
- {
- this->clientName = new char[strlen(name)+1];
- strcpy(clientName,name);
- this->clientState = state;
- }
- void Node::setName (const char *name)
- {
- strcpy(clientName,name);
- }
- void Node ::setState(const double state)
- {
- this->clientState = state;
- }
- char* Node :: getName() const
- {
- return (this->clientName);
- }
- double Node :: getState() const
- {
- return (this->clientState);
- }
- Node :: ~Node()
- {
- delete []clientName;
- }
- /* -------------------------- myQueue.cpp ---------------------------*/
- #include <iostream>
- using namespace std;
- #include "myNode.h"
- #include "myQueue.h"
- Queue :: Queue()
- {
- this->head=NULL;
- this->tail=NULL;
- }
- void Queue :: insertNode(Node n1)
- {
- if (this->head == NULL)
- this->tail = this->head = &n1;
- else
- this->tail->next=&n1;
- }
- Node * Queue :: getLast()
- {
- Node *myHead=this->head;
- this->head = this->head->next;
- return myHead;
- }
- Node * Queue :: peek()
- {
- return this->head;
- }
- bool Queue :: isEmpty()
- {
- if (this->head == NULL)
- return true;
- return false;
- }
- /* ------------------------------------------ main.cpp --------------------------------------------------*/
- #include <iostream>
- #include "myNode.h"
- #include "myQueue.h"
- using namespace std;
- void main ()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment