local merge
This commit is contained in:
Harshil Darji 2016-10-15 10:14:31 +05:30
commit d5f1da3327
3 changed files with 116 additions and 4 deletions

View File

@ -0,0 +1,51 @@
#include <iostream>
using namespace std;
void main(void)
{
int valueToConvert = 0; //Holds user input
int hexArray[8]; //Contains hex values backwards
int i = 0; //counter
int lValue = 0; //Last Value of Hex result
cout << "Enter a Decimal Value" << endl; //Displays request to stdout
cin >> valueToConvert; //Stores value into valueToConvert via user input
while (valueToConvert > 0) //Dec to Hex Algorithm
{
lValue = valueToConvert % 16; //Gets remainder
valueToConvert = valueToConvert / 16;
hexArray[i] = lValue; //Stores converted values into an array
i++;
}
cout << "Hex Value: ";
while (i > 0)
{
//Displays Hex Letters to stdout
switch (hexArray[i - 1]) {
case 10:
cout << "A";
break;
case 11:
cout << "B";
break;
case 12:
cout << "C";
break;
case 13:
cout << "D";
break;
case 14:
cout << "E";
break;
case 15:
cout << "F";
break;
default:
cout << hexArray[i - 1]; //if not an int 10 - 15, displays int value
}
i--;
}
cout << endl;
}

62
Heap Sort .cpp Normal file
View File

@ -0,0 +1,62 @@
#include <iostream>
#include <conio.h>
using namespace std;
void max_heapify(int *a, int i, int n)
{
int j, temp;
temp = a[i];
j = 2 * i;
while (j <= n)
{
if (j < n && a[j + 1] > a[j])
j = j + 1;
if (temp > a[j])
break;
else if (temp <= a[j])
{
a[j / 2] = a[j];
j = 2 * j;
}
}
a[j / 2] = temp;
return;
}
void heapsort(int *a, int n)
{
int i, temp;
for (i = n; i >= 2; i--)
{
temp = a[i];
a[i] = a[1];
a[1] = temp;
max_heapify(a, 1, i - 1);
}
}
void build_maxheap(int *a, int n)
{
int i;
for (i = n / 2; i >= 1; i--)
{
max_heapify(a, i, n);
}
}
int main()
{
int n, i, x;
cout << "Enter number of elements of array\n";
cin >> n;
int a[20];
for (i = 1; i <= n; i++)
{
cout << "Enter Element " << (i) << endl;
cin >> a[i];
}
build_maxheap(a, n);
heapsort(a, n);
cout << "Sorted Output\n";
for (i = 1; i <= n; i++)
{
cout << a[i] << endl;
}
getch();
}

View File

@ -19,7 +19,7 @@ char pop()
bool check(char x, char y)
{
if ( ( x=='(' && y==')' ) || ( x=='{' && y=='}' ) || ( x=='[' && y==']' ) || ( x=='<' && y=='>' ) )
if ((x=='(' && y==')') || (x=='{' && y=='}') || (x=='[' && y==']') || (x=='<' && y=='>'))
{
return true;
}
@ -38,12 +38,11 @@ int main()
gets(exp);
for (int i = 0; i < strlen(exp); i++)
{
if (exp[i]=='(' || exp[i]=='{' || exp[i]=='[' || exp[i]=='<')
if (exp[i]=='(' || exp[i]=='{' || exp[i]=='[' || exp[i]=='<')
{
push(exp[i]);
//show();
}
else if (exp[i]==')' || exp[i]=='}' || exp[i]==']' || exp[i]=='>')
else if (exp[i]==')' || exp[i]=='}' || exp[i]==']' || exp[i]=='>')
{
if(!check(pop(), exp[i]))
{