Skip to content

Instantly share code, notes, and snippets.

/*
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);
/*
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 {
/*
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 : ";
class node {
private:
// actual data, that is stored in the single element
int data;
//pointer to the next node
node* next;
public:
/*
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) {
/*
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
/*
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;
/*
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;
// 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;
/*
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";
}