Skip to content

Instantly share code, notes, and snippets.

void Doubly_Linked_List :: add_front(int d)
{
// Creating new node
node *temp;
temp = new node();
temp->data = d;
temp->prev = NULL;
temp->next = front;
// List is empty
/*
below we have implemented a simple function
for linear search in C
- values[] => array with all the values
- target => value to be found
- n => total number of elements in the array
*/
int linearSearch(int values[], int target, int n)
{
for(int i = 0; i < n; i++)
/*
Below we have a simple "C" program implementing
stack data structure
*/
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#define MAX 5 //Maximum number of elements that can be stored
/*
Below program is written in "C" language. This is a sample implementation of simple Queue.
*/
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#define SIZE 10
int dequeue()
{
return a[0]; //returning the first element
for (i = 0; i < tail-1; i++) //shifting all other elements
{
a[i] = a[i+1];
tail--;
}
}
/*
Below is the definition of the Node.
*/
class Node
{
private:
// our linked list will only hold int data
int data;
//pointer to the next node
node* next;
/*
Data structure below represents a simple Linked List
*/
class LinkedList
{
private:
/* define the list it self */
node *head;
public:
/*
Adds an element at the front
@param: n a pointer to the node to add
@return: the position where node is added
*/
int LinkedList :: addAtFront(node *n) {
int i = 0;
//making the next of the new Node point to Head
/*
Inserts the element at the end
@param: n as a pointer to the node to add
*/
int LinkedList :: addAtEnd(node *n) {
//If list is empty
if(head == NULL) {
//making the new Node as Head
/*
Searching for an Element in the List
@param: element in the list to look for
@returns: a pointer to the found node.
*/
node* LinkedList :: search(int x) {
node *ptr = head;
//until we reach the end or we find a Node with data x, we will keep moving