Posts

Showing posts from August, 2016

Bubble Sort

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Graph {     class BubbleSort     {         static void Main1(string[] args)         {             int n = Convert.ToInt32(Console.ReadLine());             string[] a_temp = Console.ReadLine().Split(' ');             int[] a = Array.ConvertAll(a_temp, Int32.Parse);             int Swap = 0;             for (int i = 0; i < a.Length - 1; i++)             {                 for (int j = 0; j < a.Length - 1; j++)                 {                     if (a[j] > a[j+1])                     {                         int temp = 0;                         temp = a[j];                         a[j] = a[j+1];                         a[j+1] = a[j];                         Swap = Swap + 1;                     }                 }             }             Console.WriteLine("Array is sorted in " + Swap + " swap

Graph Breadth First Search

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Graph {     class BFS     {         private List<int>[] graph_childnodes;         public BFS(int size)         {             this.graph_childnodes = new List<int>[size];             for(int i=1;i<=size;i++)             {                 graph_childnodes[i] = new List<int>();             }         }         public BFS(List<int>[] childNode)         {             graph_childnodes = childNode;         }         public int Size         {             get { return this.graph_childnodes.Length; }         }         public void AddEdge(int u,int v)         {             graph_childnodes[u].Add(v);         }         public void RemoveEdge(int u, int v)         {             graph_childnodes[u].Remove(v);         }         public bool HasEdge(int u, int v)         {             bool hasEdge = graph_

Form based Authentication from a database table in .NET

Webconfig    <authentication mode="Forms">                 <forms loginUrl="Login.aspx" defaultUrl="Welcome.aspx" timeout="2">           <credentials passwordFormat="Clear">             <user name="UserName1" password="UserName1"/>             <user name="UserName2" password="UserName2"/>           </credentials>           </forms>               </authentication>   The User credentials are stored in the Webconfig ,which is ofcourse a bad practice <authorization>       <deny users="?"></deny>       </authorization> deny User = ? no user can access the application as anonymous Login.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; using System.Configuration; using Sys

Web API and Angular Js and JSON

Web Api Controller: ---------------------------------- using ContactManager.Models; using ContactManager.Service; //using System.Web.Http.Cors; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace ContactManager.Controllers { //    [EnableCors(origins: "http://mywebclient.azurewebsites.net", headers: "*", methods: "*")]     public class ContactController : ApiController     {         private ContactRepository cntrepo;         public ContactController()         {             this.cntrepo = new ContactRepository();         }         public string Get()         {             return cntrepo.GetAllContacts();         }             } } -------------------------------------------------------------------------------------------------------------------------- Model ---------------------------------- using System; using System

DepthFirst Traversal of a graph in C#

DepthFirst Traversal of a graph in C# For understanding graphs in c# Please go through the below tutorial http://www.introprogramming.info/tag/graph-implementation/#_Toc362296541 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Graph {     class Graph     {         private List<int>[] childnodes;         public Graph(int size)         {             this.childnodes = new List<int>[size];             for (int i = 0; i < size; i++)             {                 this.childnodes[i] = new List<int>();             }         }         public Graph(List<int>[] childnode)         {             this.childnodes = childnode;         }         public int Size         {             get { return this.childnodes.Length;}         }         public void AddEdge(int u, int v)         {             childnodes[u].Add(v);         }         public void RemoveEdg

Hacker Rank : Dynamic Programming :Modified Fibonacci Series

 Hacker rank - Dynamic Programming Part 1: Given the terms ti and t(i+1), term t(i+2) will be calculated  using the relation t(i+2)=ti+t(i+1)pow2  Algo:  Dictionery m;  m[1] =ti; m[2]=t(i+1) function int fib(n) {  for(i -> 1 to n) {     if m[n]==null       return m[n]=fib[n-1]+fib[n+1]     else       return m[n]; } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace ConsoleApplication2 {     class Program     {                  static void Main(string[] args)         {             string[] str=Console.ReadLine().Split(' ');             int[] a= new int[str.Length];             for(int i=0;i<str.Length;i++)             {                 a[i]=Convert.ToInt32(str[i]);             }             Dictionary<int, BigInteger> m = new Dictionary<int, BigInteger>();                  m[1] = a[0];      

Interview Questions C#

http://csharptopicwiseques.blogspot.in/2010/09/state-management.html https://allittechnologies.blogspot.in/2015/08/Oops-interview-question-and-answer-for-beginners-and-experience.html

Interview Questions C#

http://csharptopicwiseques.blogspot.in/2010/09/state-management.html https://allittechnologies.blogspot.in/2015/08/Oops-interview-question-and-answer-for-beginners-and-experience.html Factory Design Pattern- Data access layer http://www.c-sharpcorner.com/UploadFile/db2972/factory-design-pattern/

Ref and out in method overloading

Please check  -http://www.dotnet-tricks.com/Tutorial/csharp/K0Hb060414-Difference-between-ref-and-out-parameters.html Ref The ref keyword is used to pass an argument as a reference. This means that when value of that parameter is changed in the method, it gets reflected in the calling method. An argument that is passed using a ref keyword must be initialized in the calling method before it is passed to the called method. Out The out keyword is also used to pass an argument like ref keyword, but the argument can be passed without assigning any value to it. An argument that is passed using an out keyword must be initialized in the called method before it returns back to calling method. Ref and out in method overloading Both ref and out cannot be used in method overloading simultaneously. However, ref and out are treated differently at run-time but they are treated same at compile time (CLR doesn't differentiates between the two while it created IL for ref and out).

HackerRank Challenge 4

//Funny String         //==================================         /*          * Suppose you have a String,S , of length N that is indexed from 0 to N-1 . You also have some String, R , that is the reverse of String S. S is funny if the condition S[i]-S[i-1]=R[i]-R[i-1] is true for every character i from  0 to N-1 .          *          */         static void Main(String[] args)         {             int n = Convert.ToInt32(Console.ReadLine());         string[] str= new string[n];         for(int i=0;i<n;i++)         {         str[i]= Console.ReadLine();         }                   for(int i=0 ;i<n;i++)         {             char[] arr= str[i].ToCharArray();             char[] rev_arr=new char[arr.Length];             for(int j=0;j<arr.Length;j++)                 {                  rev_arr[j]=arr[arr.Length-1 - j];                 }             string status = "Funny";             int count = 0;             for(int k=0;k<arr.Length -1;

Hackerrank Challenge 3

Insertions Sort //https://www.hackerrank.com/challenges/insertionsort1 class Program     {         static void Main(String[] args)         {             int _ar_size;             _ar_size = Convert.ToInt32(Console.ReadLine());             int[] _ar = new int[_ar_size];             String elements = Console.ReadLine();             String[] split_elements = elements.Split(' ');             for (int _ar_i = 0; _ar_i < _ar_size; _ar_i++)             {                 _ar[_ar_i] = Convert.ToInt32(split_elements[_ar_i]);             }             insertionSort(_ar);             Console.ReadLine();         }                 static void insertionSort(int[] ar)         {             bool sorted = false;                         int rightmost_num = ar[ar.Length-1];             for (int i = ar.Length-1; i > 0; i--)             {                 bool IsShift = false;                 if (rightmost_num < ar[i - 1] && sorted == false)          

HackerRank Challenge 2

Dictionary Map: ---------------------------------------------------------------------------------------------------- enter name and phone number and then search name in the given phone book list using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 {     class Program     {         static void Main(String[] args)         {             int n = Convert.ToInt32(Console.ReadLine());             Dictionary<string, string> phbook = new Dictionary<string, string>();             for (int i = 0; i < n; i++)             {                 string str = Console.ReadLine();                 char[] arr = str.ToCharArray();                 StringBuilder name = new StringBuilder();                 StringBuilder phone = new StringBuilder();                 StringBuilder current = name;                 for (int j = 0; j < str.Length; j++)                 {        

HackerRank Challenge

Construct a polygon from the given set of number. You can break the number also    class Program     {         static void Main(String[] args) {         int n = Convert.ToInt32(Console.ReadLine());         string[] a_temp = Console.ReadLine().Split(' ');         int[] a = Array.ConvertAll(a_temp,Int32.Parse);                 if(IsPolygon(a,n)==false)         {           DoCut(a,n);           }         else             Console.WriteLine(0);         Console.ReadLine();             }         static void DoCut(int[] a,int n)     {        int cut=1;        int sum = 0;        int maxnum=findGreatest(a,n);          int num1=maxnum/2;        int num2 = maxnum - num1;        int[] new_List= new int[n+1];                for(int i=0;i<n;i++)        {            if (a[i] != maxnum)            {                sum = sum + a[i];            }                        }        if (num1 > num2)        {            sum = sum + num1;            max

BootStrap Tutorial -- Coding

The below code includes example of 1) BootStrap - rows and columns 2) BootStrap - View port for responsive website in smaller devices 3) Jumbotron - The Heading element 4) Tables 5)Panels 6)Well 7)Image 8)Shadow effect <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width,initial-sca;e=1" charset="utf-8"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .colored{ background: #99FF66; } .col1colored { background: #FFA07A } .col2colored { background: #FFA500 } .col3colored { background: orange } .col4colored { background: yellow } .col5colored { background: #ccd8ff } .fontsize { fon