Saturday, October 8, 2016

Verify if the given string is valid parentheses expression in c#

You are given a string with series for parentheses. The parentheses could be only of 3 opening parentheses {, (, [ and 3 closing parentheses }, ), ]. You need to figure out if the given input are valid expression or not. Valid mean if there is proper closing and opening parentheses.

Other details and algorithm can be found here. Below is the c# implementation.

http://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/

Saturday, September 10, 2016

C# Implementation of Heap Sort

The code create the maxheap of the given array of size N and then swap the 0th index (max value) with the last index (N-1) and then again create maxheap with reduced array of size (N-1).

Continue this process unless complete array is sorted.


Thursday, March 17, 2016

Check if WMI class exist on machine through powershell

I was debugging a powershell which throw exception when it tries to GET the WMI class property of the class which does not exist on OS. I found that there are not simple example which explains the code to check the existence of wmi class and then query it property. Therefore i found a code snippet which works perfect for such scenario which check if class exists or not and then you can further query its property.


Example

if(Get-WmiObject -List | where { $_.Name -eq "Win32_PerfRawData_Counters_HyperVDynamicMemoryIntegrationService"})
{
          write-output "class exist"
}
else
{
          write-output "class do not exist"
}


I am checking the existence of wmi class "Win32_PerfRawData_Counters_HyperVDynamicMemoryIntegrationService".

On win2008 r2 / window7 and prev OS it does not exists therefore the code goes in else part.

On latest OS the if block get executed.