Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions HashTables/hashTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace std;

class hashTable
class hashTable //creating a class
{
char keys[SIZE][20];
int values[SIZE];
Expand All @@ -29,8 +29,8 @@ void hashTable :: get()
cout<<"Enter the key: ";
cin>>key;

int index = hashFunction(key);
int index = hashFunction(key); //initialising

while (strcmp(keys[index],"\0") != 0)
{
/* Loop runs till it gets an NULL string */
Expand All @@ -44,7 +44,7 @@ void hashTable :: get()

index = (index+1) % SIZE;
}

cout<<"Key not found!"<<endl;
}

Expand All @@ -69,7 +69,7 @@ void hashTable :: put()
}

index = (index+1) % SIZE;
}
}

cout<<"Enter the value: ";
cin>>value;
Expand All @@ -83,7 +83,7 @@ int hashTable :: hashFunction(char key[])
e.g- "Hello" has ASCII value of 500, so index is 0 */

int sum=0;

for(int i=0; i < strlen(key); i++)
{
sum = sum + key[i];
Expand All @@ -106,7 +106,7 @@ int main()
system("clear");
char choice[2];
int quit = 0;

hashTable obj;
menu();
while (!quit)
Expand All @@ -124,7 +124,7 @@ int main()

case 3: quit++;
break;

default: cout<<"Wrong Input!"<<endl;
}
}
Expand Down
17 changes: 8 additions & 9 deletions Heap/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace std;


class Heap
class Heap //creating a Heap Class
{
int data[heapSize];
int current;
Expand All @@ -19,7 +19,7 @@ class Heap
}
current = -1;
}
void insert(int);
void insert(int); //Declaring the functions
bool isFull();
void fixHeap(int);
void heapSort();
Expand All @@ -43,7 +43,7 @@ void Heap :: insert(int value)
cout<<"Heap is Full!"<<endl;
return;
}

current += 1;
/* TIP- Element fills in sequence in heap i.e 0, 1, 2, 3, 4... */
data[current] = value;
Expand Down Expand Up @@ -85,7 +85,7 @@ void Heap :: heapSort()
data[0] = temp;

cout<<data[current-i]<<"\t";

max_heap(0, current -i - 1);
}
cout<<endl;
Expand Down Expand Up @@ -116,7 +116,7 @@ void Heap :: max_heap(int rootIndex, int UB)
else
childToSwap = leftChild;
}

if (data[rootIndex] < data[childToSwap])
{
temp = data[rootIndex];
Expand All @@ -128,7 +128,7 @@ void Heap :: max_heap(int rootIndex, int UB)
/* After this the children hold good the max_heap property */
break;
}

rootIndex = childToSwap;
leftChild = 2*rootIndex+1;
rightChild = 2*rootIndex+2;
Expand Down Expand Up @@ -167,7 +167,7 @@ int main()
menu();
char choice[2];
int quit = 0, value;
Heap obj;
Heap obj; //creating an object
while(!quit)
{
cout<<"Please Enter your choice: ";
Expand All @@ -179,7 +179,7 @@ int main()
cin>>value;
obj.insert(value);
break;

case 2: cout<<"Deleted Item is :"<<obj.deleteRoot()<<endl;
break;

Expand All @@ -198,4 +198,3 @@ int main()

return 0;
}

57 changes: 27 additions & 30 deletions LinkedList/LinkedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace std;

class node
class node //creating a node class
{
public:
int data;
Expand All @@ -23,30 +23,31 @@ class linkedList
{
head = NULL;
tail = NULL;
nodeCount = 0;
nodeCount = 0;
}
void insertAtHead(int);
void insertAtTail(int);
void displayData();
void displayDetail();
int deleteHead();
int deleteTail();
node* find(int, node**);
int deleteTarget(int);
void printReverse();
void reverse(node*);
~linkedList()
{
node* prev=NULL;
node* temp=head;
while(temp!=NULL)
{
//cout<<"Memory is being freed"<<endl;
prev=temp;
temp=prev->next;
free(prev);
}
}
void insertAtHead(int); //Declaring the functions
void insertAtTail(int);
void displayData();
void displayDetail();
int deleteHead();
int deleteTail();
node* find(int, node**);
int deleteTarget(int);
void printReverse();
void reverse(node*);

~linkedList()
{
node* prev=NULL;
node* temp=head;
while(temp!=NULL)
{
//cout<<"Memory is being freed"<<endl;
prev=temp;
temp=prev->next;
free(prev);
}
}
};

void linkedList :: insertAtHead(int value)
Expand Down Expand Up @@ -79,8 +80,8 @@ void linkedList :: insertAtTail(int value)
temp=(node*)malloc(sizeof(node));
if(temp==NULL)
{
cout<<"Unable to allocate memory for Node"<<endl;
return;
cout<<"Unable to allocate memory for Node"<<endl;
return;
}
temp->data=value;
temp->next=NULL;
Expand Down Expand Up @@ -346,7 +347,3 @@ int main()
}
}
}