Posts

Showing posts with the label SDET

Hex to Decimal

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HexToDec { class Program { static void Main(string[] args) { string hex = Console.ReadLine(); int Total = 0; //TBD: Need to check for other characters are entered for (int i = 0; i <= hex.Length - 1; i++) { switch (Convert.ToChar(hex[i].ToString().ToUpper())) { case 'A': Total = Total + 10*((Int32)Math.Pow(16,hex.Length-1-i)); break; case 'B': Total = Total + 11 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'C': Total = Total + 12 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'D': Total = Total + 13 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'E': Total = Total + 14 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'F': Total = Total + 15 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; default: Total = Total + Convert.ToInt32(hex[i].ToString()) * ((Int...

Binary Search Tree Operations

#include "iostream" #include "cstdlib" using namespace std; class BinarySearchTree { private: struct tree_node { int data; tree_node* left; tree_node* right; }; tree_node* root; public: BinarySearchTree() { root = NULL; } void Print_PreOrder(); void Print_PostOrder(); void Print_InOrder(); void inorder(tree_node*); void preorder(tree_node*); void postorder(tree_node*); void insert(int); }; void BinarySearchTree::insert(int d) { tree_node* current = new tree_node; current->data = d; current->left = NULL; current->right = NULL; tree_node* parent; parent = root; tree_node* temp; if(root == NULL) { root = current; } else { while(parent) { temp = parent; if(current->data > parent->data ) { parent = parent->right; } else { parent = parent->left; } } if(current->data > temp->data) { temp->right = current; } else { temp->left = current; } } } void Bina...

C# - Reference Example

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace reference { class Program { static void Main(string[] args) { int i = 5; Method(ref i); Console.WriteLine(i.ToString()); Console.ReadLine(); } static void Method(ref int j) { j = j + 7; } } }

string reverse

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stringreverse { class Program { static void Main(string[] args) { string first; int j=0; Console.WriteLine("Enter the first string"); first = Console.ReadLine(); char[] firstArr = first.ToCharArray(); char[] secondArr = first.ToCharArray(); for (int i = first.Length - 1; i >= 0; i--) { secondArr[j] = firstArr[i]; j++; } Console.WriteLine(secondArr); Console.ReadLine(); } } }

First repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace FirstRepeatedCharacter1 { class Program { static void Main(string[] args) { Console.WriteLine("Enter the string"); string str = Console.ReadLine(); if (str == "") { Console.WriteLine("string is empty"); Console.ReadLine(); return; } bool repeated = false; Hashtable strhash = new Hashtable(); foreach (char ch in str) { if (strhash.ContainsValue(ch)) { Console.WriteLine("First non repeated character: " + ch); repeated = true; break; } else { strhash.Add((int)ch, ch); } } if (repeated == false) { Console.WriteLine("No repeated characters"); } Console.ReadLine(); } } }