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
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 |
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
/* | |
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++) |
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
/* | |
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 |
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
/* | |
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 |
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
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--; | |
} | |
} |
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
/* | |
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; |
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
/* | |
Data structure below represents a simple Linked List | |
*/ | |
class LinkedList | |
{ | |
private: | |
/* define the list it self */ | |
node *head; | |
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 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 |
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
/* | |
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 |
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
/* | |
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 |
OlderNewer