Skip to content

VDonC#ev

C{}d3

Categories

  • Abstract Data Structures
  • C# Algorithms
  • C# Snippets
  • Combinatorics
  • Java Algorithms
  • Java Snippets
  • Javascript Algorithms
  • PHP

Useful

  • Combinatorial Examples

MINI

Guess the number
Text 2 Array
Notepad

Recent Posts

  • Look And Say Sequence – PHP 7.4
  • Look and Say Sequence in PHP
  • Look and Say Sequence Generator – Javascript (ECMAscript 6)
  • Shortest Path In Graph – Dijkstra’s Algorithm – C# Implementation
  • Minimum Spanning Tree – Kruskal Algorithm – C# Implementation

Tag: quick

How to swap 2 integers without temp variable using XOR

using System;

public static class SwapTwoIntegers
{
    private static void Main()
    {
        var a = 55;
        var b = 69;

        SwapInts(ref a, ref b);

        Console.WriteLine(a); // 69
        Console.WriteLine(b); // 55
    }

    private static void SwapInts(ref int a, ref int b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
}
Posted on April 9, 2016December 1, 2019Categories C# SnippetsTags how to, quick, xor
Proudly powered by WordPress