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
/* | |
Deleting a Node from the List | |
@param: x is the node to delete | |
*/ | |
node* LinkedList :: deleteNode(int x) { | |
// call the method to search the Node with data x first | |
node *n = search(x); | |
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
/* | |
checks if linked list is empty or not. | |
@returns 1 if empty and 0 if NOT empty | |
*/ | |
int LinkedList :: isEmpty() { | |
if(head == NULL) { | |
return 1; | |
} | |
else { |
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
/* | |
Main part of the program that executes all parts of the Linked List application. | |
This can be used to test Linked List. | |
*/ | |
int main() { | |
LinkedList L; | |
//We will ask value from user, read the value and add value to our Node | |
int x; | |
cout << "Please enter an integer value : "; |
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
class node { | |
private: | |
// actual data, that is stored in the single element | |
int data; | |
//pointer to the next node | |
node* next; | |
public: |
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
/* | |
adds a new element to the front of circular linked list | |
@param: m as a new node | |
@returns: the position, where new node was added | |
*/ | |
int CircularLinkedList :: addAtFront(node *n) { | |
int i = 0; | |
/* If the list is empty (the head is poiting to NULL) */ | |
if(head == NULL) { |
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
/* | |
adds an element at the end of Circular Linked List | |
@param: n as node to add | |
*/ | |
int CircularLinkedList::addAtEnd(node *n) { | |
//If list is empty | |
if(head == NULL) { | |
//making the new Node as Head |
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
/* | |
search Circular Linked List for specific value | |
@param: x is a value to look for | |
@returns: a pointer to the found node or NULL if nothing found | |
*/ | |
node* CircularLinkedList :: search(int x) { | |
node *ptr = head; | |
while(ptr != NULL && ptr->data != x) { | |
//until we reach the end or we find a Node with data x, we keep moving | |
ptr = ptr->next; |
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
/* | |
deletes node withe given value | |
*/ | |
node* CircularLinkedList :: deleteNode(int x) { | |
//searching the Node with data x | |
node *n = search(x); | |
node *ptr = head; | |
if(ptr == NULL) { | |
cout << "List is empty"; | |
return NULL; |
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
// Maximum size of array or Dequeue | |
#define SIZE 5 | |
class Dequeue | |
{ | |
private: | |
//front and rear to store the head and tail pointers | |
int *arr; | |
int front, rear; |
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
/* | |
pushes the element to the front | |
@param: a key to insert at the front | |
*/ | |
void Dequeue::push_front(int key) | |
{ | |
if(full()) | |
{ | |
cout << "OVERFLOW\n"; | |
} |