Thursday, May 16, 2013


used in operatonal research LP(linear programming)
The Simplex Algorithm

Simplex method

Resolve using the Simplex Method the following problem:
Maximize Z = f(x,y) = 3x + 2y
subject to: 2x + y ≤ 18
  2x + 3y ≤ 42
  3x + y ≤ 24
  x ≥ 0 , y ≥ 0
Are considerated the following phases:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simplex_Method
{
    class simplex
    {
        int countslock;
        int frow;
        int fcol;
        double[,] dt = { { 1, -8, -6, 0, 0, 0, 0 }, { 0, 2, 7, 1, 0, 100, 0 }, { 0, 1, 3, 0, 1, 50, 0 } };
        double[] temprowdata1 ;
       

        public simplex()
        {
           
            Console.WriteLine("the data is");
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                  Console.Write( dt[i,j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine();
            temprowdata1 =  new double[dt.GetLength(1)];
            aditioniteration();
            //operation(dt);
            //double[] tempdt = {30,20,50,15,10,100};
            //ratiorow(tempdt);
           // Console.WriteLine(dt.GetLength(0));
        }
        public string check_cons(string a)
        {
            countslock++;
            if (a.Contains("<="))
            {
                return a.Replace("<", "+s" + countslock);
            }
            else if (a.Contains(">="))
            {
                return a.Replace(">", "-s" + countslock);
            }
            return "error";
        }
        public string[] dataextract(string a)
        {
           
            string[] data;
            int dtcounter =0;
            data = new string[a.Length];
            string sec = "";
            for (int i = 0; i <a.Length; i++)
            {
   
                if (a[i] != 'x')
                {
                    sec += a[i];
                }
                else { i++;
                    data[dtcounter] = sec; dtcounter++; sec = ""; }
             
            }
           data[dtcounter] = sec;
            for (int i = 0; i <data.Length; i++)
            {
                if (data[i] != null)
                {
                    if (data[i].Length == 1 && i > 0 )
                    { data[i] += "1"; }
                    if (data[i].Contains("="))
                    {
                 
                        string[] s = data[i].Split('=');
                        bool ass = false;
                        foreach (var item in s)
                        {
                            if (ass)
                            { data[i + 1] = item; }
                            if (item.Contains('-'))
                            { data[i] = "-1"; ass = true;  }
                            else if(!item.Contains('-') && !ass) { data[i] = "1"; ass = true; }
                        }
                    }
                }
           
            }
            //for (int i = 0; i < data.Length; i++)
            //{
            //    Console.WriteLine(data[i]);
            //}
         
            return data;
        }

        public void problemsolve(double[,] a)
        {
            if (minind(a) > 0)
            {

            }
        }


        public double[] operation(double[,] a)
        {
            int row = 0;
            int coloumn = 0;
            double pivotelement = 0;
            double m = 0;
            double[] ratiodata = new double[a.GetLength(0)];
            bool readytogo = false;
            for (int i = 0; i < a.GetLength(0); i++)
            {
                //least data containg coloumn index
                if (a[0, i] < m)
                {
                    m = a[0, i];
                    coloumn = i;
                }
            }
            if (readytogo)
            {
                for (int i = 1; i < a.GetLength(0); i++)
                {
                    //least ratio calculating
                    ratiodata[i] = (a[i, a.GetLength(1) - 2] / a[i, Convert.ToInt32(coloumn)]);
                }

                //selecting row data for next operation to bring zero in data one
                if (minratiocheck(ratiodata))
                {
                    double[] temprowdata = new double[a.GetLength(1)];

                    row = ratiorow(ratiodata);
                    pivotelement = a[row, coloumn];

                    if (pivotelement > 0 && pivotelement == 1)
                    {
                        // if pivot = 1 take data as it
                        for (int i = 0; i < a.GetLength(1); i++)
                        {
                            temprowdata1[i] = (a[row, i]);
                            Console.WriteLine(temprowdata[i]);
                        }
                    }
                    else
                    {
                        //pivot element row equalizing to one and then take data
                        for (int i = 0; i < a.GetLength(1); i++)
                        {
                            temprowdata1[i] = (a[row, i] / a[row, coloumn]);
                        }

                    }
                }
                frow = row;
                fcol = coloumn;
                return temprowdata1;
            }
        }
        public void aditioniteration()
        {
            double[] arr = operation(dt);
            double[] arrtemp = new double[arr.Length];
            double leastvalue = dt[0, fcol];
            for (int i = 0; i <arr.Length; i++)
            {
                 arrtemp[i] = arr[i] * (leastvalue *(-1));
                Console.WriteLine(arrtemp[i]);
            }
        }
        public bool minratiocheck(double[] ratio)
        {
            for (int i = 0; i < ratio.Length; i++)
            {
                if (ratio[i] > 0)
                {
                    return true;
                }
            }
            return false;
        }
        public int ratiorow(double[] ratio)
        {
            double m =500000000;
            int row = 0;
            for (int i = 0; i < ratio.Length; i++)
            {
                if (m > ratio[i] && ratio[i] != 0)
                {
                    if (ratio[i] > 0)
                    {
                        m = ratio[i];
                        row = i;
                    }

                }
     
            }
            return row;
        }
        public double minind(double[,] a)
        {
            double m = 0;
            double ind = 0;
            for (int i = 0; i < a.GetLength(0); i++)
            {
                if (a[0, i] < m)
                {
                    m = a[0, i];
                    ind = i;
                }
            }
            if (ind > 0)
            {
                return ind;
            }
            return 0.0;
        }
        public void ratiocheck(double[,] a)
        {
            double minvalue = minind(a);
            double[] ratiodt = new double[a.GetLength(0)];


            Console.WriteLine("minvalue   " + minvalue);
            for (int i = 1; i < a.GetLength(0); i++)
            {
                ratiodt[i] = a[i, Convert.ToInt32(minvalue)] / a[i, a.GetLength(1) - 2];
                Console.WriteLine(ratiodt[i]);
                Console.WriteLine(a[i, a.GetLength(1) - 1]+" world war");
            }          
        }
    }
    class Program
    {
       
   
        static void Main(string[] args)
        {
            simplex sim = new simplex();


            /*
           
            int[] arr = { 0, 0,50, 50, 60 ,-90,0,0,10,10,20};
            int m = 1000000;
            for (int i = 1; i < arr.Length; i++)
            {
                if (m > arr[i] && arr[i] != 0 )
                {
                    if (arr[i] > 0)
                    {
                        m = arr[i];
                        Console.WriteLine(m);
                        Console.WriteLine(i);
                    }
                }
            }
              important min function
            */
            /*
        //    sim.dataextract("");
            string[] constraint = { "20x1-10x2+0x3>=50", "1x1+3x2+x3>=25", "-1x1+2x2+0x3<=26" };
            //for (int i = 0; i < constraint.Length; i++)
            //{

            //    string[] values = sim.dataextract(sim.check_cons(constraint[i]));
         
            //    foreach (var item in values)
            //    {
            //        if (i >= 1)
            //        {
            //            Console.Write(item + " ");
            //        }
            //        Console.WriteLine();
                 
            //    }

            //}



            //string maxz = "Z=2x1+3x2+4x3";
            //maxz = maxz.Replace("+", "-");
            //maxz = maxz.Replace("=", "-");
            //maxz += "=0";
            //Console.WriteLine(maxz);


            for (int i = 0; i < constraint.Length; i++)
            {
                //   Console.WriteLine(sim.check_cons(constraint[i]));
                string[] values = sim.dataextract(sim.check_cons(constraint[i]));
                foreach (var item in values)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("refind data");
            sim.dataextract("90x1-7x2+1x3-s2=25");
            */
        }
    }
}

Android simple application by adding 2 values

ok this is csharp blog and quit inactive for a long time i have been not posting any thing about c-sharp and that is because i don't much work to do on c-sharp for. but main purpose of this is blog is online codes for programming whether its c-sharp or java or android.
so today i am going to post the complete code of a little android test application.

XML

<?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="ADDITION OF NUMBERS"
     android:id="@+id/textView1"
     android:layout_x="73dip"
     android:layout_y="28dip"></TextView>
    <TextView android:layout_width="wrap_content"
    android:layout_x="36dip"
    android:layout_height="wrap_content"
    android:text="First Amount"
    android:id="@+id/textView2"
    android:layout_y="80dip"></TextView>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="172dip"
    android:id="@+id/amount1"
    android:layout_height="wrap_content"
    android:layout_y="62dip"></EditText>
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Second Amount"
    android:id="@+id/textView3"
    android:layout_x="36dip"
    android:layout_y="169dip"></TextView>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="169dip"
    android:id="@+id/amount2"
    android:layout_height="wrap_content"
    android:layout_y="152dip"></EditText>
    <Button android:layout_width="wrap_content"
    android:id="@+id/calculate"
    android:layout_x="41dip"
    android:layout_height="wrap_content"
    android:text="Calculate"
    android:layout_y="232dip"></Button>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="172dip"
    android:id="@+id/tt"
    android:layout_height="wrap_content"
    android:layout_y="232dip"></EditText>
    </AbsoluteLayout>

Main Activity
package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

EditText amount1;
 EditText amount2;
 TextView tt;
 Button calculate;
 double x=0;
 double y=0;
 double z=0;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     initControls();
 }
 private void initControls()
 {
     amount1=(EditText)findViewById(R.id.amount1);
     amount2=(EditText)findViewById(R.id.amount2);
     tt=(TextView)findViewById(R.id.tt);
     calculate=(Button)findViewById(R.id.calculate);
     calculate.setOnClickListener(new Button.OnClickListener(){public void onClick
     (View  v) { calculate();}});
 }
 private void calculate()
 {
     x=Double.parseDouble(amount1.getText().toString());
     y=Double.parseDouble(amount2.getText().toString());
     z=x+y;
     tt.setText(Double.toString(z));
     calculate.setText(Double.toString(z));
 }
}

Friday, November 30, 2012

Database connectivity.

Connection string for Sql and msacces 
  • SQL connection string:Data Source=(local) ;Initial Catalog=myDataBase.mdb ;Integrated Security=SSPI;
  •  MSacces connection string (2003): Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;
  •  MSacces connection string (2007): Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\mydatabase.mdb;

Sample code Sql:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace database_manupulation
{
    public partial class Form1 : Form
    {
        public string constring = "Data Source=TAHMED\\SQLEXPRESS;Initial Catalog=hospital;Integrated Security=TRUE";
        bool max = true;
        bool min = false;
        SqlConnection con = new SqlConnection("Data Source=(local) ;Initial Catalog=hospital;Integrated Security=TRUE");
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        public Form1()
        {
           
            InitializeComponent();
            timer1.Start();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            da.SelectCommand = new SqlCommand("SELECT * FROM patient", con);
            ds.Clear();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                da.InsertCommand = new SqlCommand("INSERT INTO patient VALUES(@patient_name,@phy_id)", con);
                //da.InsertCommand = new SqlCommand("INSERT INTO treatment VALUES(@patient_id,@phy_id)", con);


                da.InsertCommand.Parameters.Add("@patient_name", SqlDbType.VarChar).Value = textBox1.Text;

                //da.InsertCommand.Parameters.Add("@phy_id", SqlDbType.Int).Value = Convert.ToInt32(textBox2.Text);

                //da.InsertCommand.Parameters.Add("@patient_id", SqlDbType.Int).Value = Convert.ToInt32(textBox3.Text);

                da.InsertCommand.Parameters.Add("@phy_id", SqlDbType.Int).Value = Convert.ToInt32(textBox2.Text);

                con.Open();
                da.InsertCommand.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception v)
            {
                con.Close();
                MessageBox.Show(v.Message);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            da.DeleteCommand = new SqlCommand("DELETE FROM patient WHERE patient_id="+Convert.ToInt32( textBox2.Text), con);
          //  da.DeleteCommand = new SqlCommand("DELETE FROM treatment WHERE treatment_id=" +Convert.ToInt32( textBox2.Text), con);

            con.Open();
            da.DeleteCommand.ExecuteNonQuery();
            con.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           label2.Text = Convert.ToString( DateTime.Now.ToUniversalTime());
            //label2.Text = DateTime.Now.ToLongTimeString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
           //dataGridView2.Columns.Add("this", "THIS");
          // dataGridView2.Rows.Add("THis", 3);
            double a = Convert.ToDouble(dataGridView2.Rows[0].Cells[1].Value.ToString());
            double b = Convert.ToDouble(dataGridView2.Rows[1].Cells[1].Value.ToString());
            double c = Convert.ToDouble(dataGridView2.Rows[2].Cells[1].Value.ToString());
            double d = Convert.ToDouble(dataGridView2.Rows[3].Cells[1].Value.ToString());
            double aa = Convert.ToDouble(dataGridView2.Rows[4].Cells[1].Value.ToString());
            double zz = a + b +c+d+aa;
            ///dataGridView2.Columns.Add("1", "want check");
            label3.Text = (zz/5).ToString();
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //DataTable dt = new DataTable();
            //dt.Columns.Add("this");
            //DataRow a = dt.NewRow();
            //a[1] = "this and no regret";
            //label3.Text = a[1].ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {

            if (max)
            {
                this.WindowState = FormWindowState.Maximized;
                min = true;
                max = false;
            }
            else  { this.WindowState = FormWindowState.Normal; max = true; min = false;}
           
            //dataGridView2.Rows.Clear();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView2.Rows.Add();
            dataGridView2.Rows[0].Cells[0].Value = "user";
            dataGridView2.Rows[0].Cells[1].Value = "3.5";
            dataGridView2.Rows[0].Cells[2].Value = "good";
            toolStripProgressBar1.Value = 20;
dataGridView2.Rows.Add();
            dataGridView2.Rows[1].Cells[0].Value = "user";
            dataGridView2.Rows[1].Cells[1].Value = "4";
            dataGridView2.Rows[1].Cells[2].Value = "good";
            toolStripProgressBar1.Value = 40;
            dataGridView2.Rows.Add();
            dataGridView2.Rows[2].Cells[0].Value = "user";
            dataGridView2.Rows[2].Cells[1].Value = "3";
            dataGridView2.Rows[2].Cells[2].Value = "good";
            toolStripProgressBar1.Value = 60;
            dataGridView2.Rows.Add();
            dataGridView2.Rows[3].Cells[0].Value = "user";
            dataGridView2.Rows[3].Cells[1].Value = "2.5";
            dataGridView2.Rows[3].Cells[2].Value = "good";
            toolStripProgressBar1.Value = 80;
            dataGridView2.Rows[4].Cells[0].Value = "user";
            dataGridView2.Rows[4].Cells[1].Value = "1.5";
            dataGridView2.Rows[4].Cells[2].Value = "good";
            toolStripProgressBar1.Value = 100;
            toolStripStatusLabel1.Text = "data loaded to datagrid view";
        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            toolStripStatusLabel1.Text = "windows color red";
            toolStripProgressBar1.Value = 0;
            this.BackColor = Color.Red;
        }
    }
}
 

Sunday, May 13, 2012

Des cipher with 10 bit key generator. complete algo and program with source code

 Screen shot of Des cipher GUI program
Source code will be Available .


https://docs.google.com/open?id=0B_GqGJH_ajS9YlFPaWRvY2xEYkk

Wednesday, December 28, 2011

Algorithm's

  1. Tower of Hannoi
  2. Gaussian Elimination
  3. Matrix Multiplication
  4. Jhon trotter(permutation)
  5. Lexographic (permutation)
ALGORITHM TOWER OF HANOI as TOH (n,A,B,C)
{
//if only one disk has to moved
     If(n=1) then
      {
        Write(“The peg moved from A to C”)
         Return
      }
    else
     {
       //move top (n-1) disk from A to B using C
      TOH(n-1,A,B,C)
    // move remaining disk from B to C using A
    TOH(n-1,B,C,A)
   }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace algorithms
{
    class algo
    {
        int count;
 
        public void towerofhannoi(int n,char w,char y,char z)
        {
            count++;
            if (n == 1)
            {
                Console.WriteLine("disc moved from {0} to {1} using {2}", w,y,z);
              
            }
            else
            {
                towerofhannoi(n - 1, w,y,z);
                towerofhannoi(1, w, z,y);
                towerofhannoi(n - 1, y ,z, w );
            }
           
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            algo hanoi = new algo();
            hanoi.towerofhannoi(3,'A', 'B' ,'C');

        }
    }
}

Gauss jordan row elimination algorithm:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace new_algo
{
    class algo
    {
        int[,] a;
        int tnum;
        public algo(int no)
        {
            tnum = no;
            a = new int[tnum, tnum + 1];
        }

        public void show()
        {
            Console.WriteLine("enter the value");
            for (int i = 0; i < tnum; i++)
            {
                for (int j = 0; j < tnum + 1; j++)
                {
                    Console.Write("M[{0},{1}]=", i, j);
                    a[i, j] = Convert.ToInt32(Console.ReadLine());
                }
                //a[i, a.GetLength(0)] = b[i];
            }
            Console.WriteLine("Displaying the values in Matrix");
            for (int i = 0; i < tnum; i++)
            {
                for (int j = 0; j < tnum + 1; j++)
                {
                    Console.Write("{0:F2}\t",a[ i, j]);
                }
                Console.WriteLine();//a[i, a.GetLength(0)] = b[i];
            }
            for (int i = 0; i < tnum; i++)      // i representing no of rows
            {
                int temp = a[i, i];

                for (int j = 0; j < tnum + 1; j++)    // j representing no of columns
                {
                    a[i, j] = a[i, j] / temp;  // To Store Multipliers
                }

                for (int k = 0; k < tnum; k++)  // k representing Rows on which operation is
                {                               // being performed. To create zeros below &
                    temp = a[k, i]; // above the main diagonal.
                    if (i != k)
                    {
                        for (int j = 0; j < tnum + 1; j++) // j represents no of colums on which operation is being performed
                        {
                            a[k, j] = a[k, j] - (temp * a[i, j]);
                        }
                    }
                }

            }
            Console.WriteLine("solved matrix");
            for (int i = 0; i < tnum; i++)
            {
                for (int j = 0; j < tnum + 1; j++)
                {
                    Console.Write("{0:F2}\t", a[i, j]);
                }
                Console.WriteLine();//a[i, a.GetLength(0)] = b[i];
            }
        }
    }

   
    class Program
    {
        static void Main(string[] args)
        {
            algo a = new algo(2);
            a.show();

        }
    }
}

MATRIX MULTIPLICATION ALGORITHM ON N*N ARRAYS
ALGORITHM MATRIX MULTIPLICATION (A[0…n-1], B[0…n-1])

//Multiplying two n*n matrices by the definition base algorithm
//Input: Two n*n matrices A and B
//Output: matrix C=A*B


For i<----0 to n-1 do
    For j<----0 to n-1 do
         C[i,j] <----0
    For k<----0 to n-1 do
   C[i,j] <---- C[i,j]+A[i,k]*B[k,j]

return C


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace algorithms
{

    class Program
    {
        static void Main(string[] args)
        {
          
            int[,] a = new int[,]{{1,3,4},{6,2,4}};
            int[,] b = new int[,]{{5,4,8},{3,2,7}};
            int[,] c = new int[, ] {{5,4,8},{3,2,7}};

            for (int i = 0; i < c.GetLength(0); i++)
            {
                for (int j = 0; j < c.GetLength(1); j++)
                {
                    c[i, j] = 0;
                    for (int k = 0; k < b.GetLength(0); k++) // OR k<b.GetLength(0)
                        c[i, j] = c[i, j] + a[i, k] * b[k, j];
                }
            }
        
                for (int row = 0; row  < c.GetLength(0); row++)
                {
                    for (int col = 0; col < c.GetLength(1); col++)
                    {
                        Console.WriteLine("{0}",c[row, col]);
                        Console.WriteLine();
                    }
                }
        }
    }
}

Jhon trotter algorithm()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace algo
{
    public class JT
    {

        public void perm(int N)
        {
            int[] p = new int[N];     // permutation
            int[] pi = new int[N];     // inverse permutation
            int[] dir = new int[N];     // direction = +1 or -1
            for (int i = 0; i < N; i++)
            {
                dir[i] = -1;
                p[i] = i;
                pi[i] = i;
            }
            perm(0, p, pi, dir);
            Console.Write("   (0 1)\n");
        }

        public void perm(int n, int[] p, int[] pi, int[] dir)
        {

            if (n >= p.Length)
            {
                for (int i = 0; i < p.Length; i++)
                    Console.Write(p[i]);
                return;
            }
            perm(n + 1, p, pi, dir);
            for (int i = 0; i <= n - 1; i++)
            {

                // swap
                Console.Write("   {0} {1}\n", pi[n], pi[n] + dir[n]);
                int z = p[pi[n] + dir[n]];
                p[pi[n]] = z;
                p[pi[n] + dir[n]] = n;
                pi[z] = pi[n];
                pi[n] = pi[n] + dir[n];

                perm(n + 1, p, pi, dir);
            }
            dir[n] = -dir[n];
        }

        class Program
        {
            static void Main(string[] args)
            {
                JT a = new JT();
                Console.Write("Enter value:");
                int x = Convert.ToInt32(Console.ReadLine());
                a.perm(x);
            }
        }
    }
}

Lexicographic algorithm ()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace algo
{
    public class PermutationsLex
    {

        public void show(int[] a)
        {
            for (int i = 0; i < a.Length; i++)
                Console.Write("{0}", a[i]);
            Console.WriteLine("\n");
        }

        public void swap(int[] a, int i, int j)
        {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

        public bool hasNext(int[] a)
        {
            int N = a.Length;

            // find rightmost element a[k] that is smaller than element to its right
            int k;
            for (k = N - 2; k >= 0; k--)
                if (a[k] < a[k + 1]) break;
            if (k == -1) return false;

            // find rightmost element a[j] that is larger than a[k]
            int j = N - 1;
            while (a[k] > a[j])
                j--;
            swap(a, j, k);

            for (int r = N - 1, s = k + 1; r > s; r--, s++)
                swap(a, r, s);

            return true;
        }

        public void perm(int N)
        {

            // initialize permutation
            int[] a = new int[N];
            for (int i = 0; i < N; i++)
                a[i] = i;

            // print permutations
            show(a);
            while (hasNext(a))
                show(a);
        }


        class Program
        {
            static void Main(string[] args)
            {
                PermutationsLex a = new PermutationsLex();
                Console.Write("Enter value:");
                int x = Convert.ToInt32(Console.ReadLine());
                a.perm(x);
            }
        }
    }
}

used in operatonal research LP(linear programming) The Simplex Algorithm Simplex method Resolve using the Simple...