Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef hello_CPP
- #define hello_CPP
- #include <iostream>
- using namespace std;
- #include "hello.h"
- hello::hello()
- {
- Front = NULL;
- Rear = NULL;
- Count = 0;
- }
- hello::~hello()
- {
- }
- bool hello::isEmpty()
- {
- if (Front==NULL&&Rear==NULL&&Count==0)return true;
- else return false;
- }
- void hello::displayAll()
- {
- cout << endl;
- if (isEmpty()) cout << "[ empty ]" << endl;
- else
- {
- //cout << Front->Elem << endl;
- Node *p;
- p = Front;
- while(p!=NULL)
- {
- cout << p->Elem << endl;
- p = p->Next;
- }
- }
- }
- void hello::addRear(el_t NewNum)
- {
- if (isEmpty())
- {
- Node *First;
- First = new Node;
- Front = First;
- Rear = First;
- Count++;//Count line
- First->Elem = NewNum;
- }
- else
- {
- Rear->Next = new Node;
- Rear = Rear->Next;
- Rear->Elem = NewNum;
- Rear->Next = NULL;
- Count++;//Count line
- }
- }
- void hello::deleteFront(el_t& OldNum)
- {if (isEmpty()){throw Underflow();}
- else
- {
- OldNum = Front->Elem;
- Node *Second;
- Second = Front->Next;
- delete Front;
- Front = Second;
- if(Count==1)
- {
- Front = NULL;
- Rear = NULL;
- }
- Count--;//Count line
- }
- }
- void hello::addFront(el_t NewNum)
- {
- if (isEmpty())
- {
- addRear(NewNum);//References rear
- }
- else
- {
- Node *p;
- p = new Node;
- p->Next = Front;
- Front = p;
- Front->Elem = NewNum;
- Count++;//Count line
- }
- }
- void hello::deleteRear(el_t& OldNum)
- {if (isEmpty()){throw Underflow();}
- if (Count == 1) deleteFront(OldNum);
- else
- {
- OldNum = Rear->Elem;
- Rear = p;
- Rear->Next = NULL;
- Count--;//Count line
- }
- }
- void hello::deleteIth(int I, el_t& OldNum)
- {
- int i;
- if (I<1||I>Count){throw OutOfRange();}
- else
- {
- if (I == 1) deleteFront(OldNum);
- else
- {
- Node *p;
- Node *q;
- p = Front;
- q = Front;
- while (i<I)
- {
- p = p->Next;
- i++;
- }
- i = 0;
- while (i<(I-1))
- {
- q = q->Next;
- i++;
- }
- OldNum = p->Elem;
- //p->Elem = NULL;
- delete p;
- Rear = q;
- Rear -> Next = NULL;
- Count--;//Count line
- }
- }
- }
- void hello::addbeforeIth(int I, el_t newNum)
- {
- int i;
- i = 0;
- if (!(I<1||I>Count+1))
- {
- if (isEmpty()||I==Count+1)
- {
- addRear(newNum);//References rear
- return;
- }
- if (I == 1)
- {
- addFront(newNum);
- return;
- }
- else
- {
- Node *p;
- Node *q;
- p = Front;
- q = Front;
- while (i<I)
- {
- p = p->Next;
- i++;
- }
- i = 0;
- while (i<(I-1))
- {
- q = q->Next;
- i++;
- }
- Node *r;
- r = new Node;
- r->Elem = newNum;
- q->Next = r;
- r->Next = p;//qrp
- Count++;//Count line
- }
- }
- else{throw OutOfRange();}
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement