Skip to content
This repository was archived by the owner on Oct 7, 2019. It is now read-only.

added code in java for lcs #167

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
40 changes: 40 additions & 0 deletions dynamic_programing/longest_common_subsequence/java/lcs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import java.util.*;
public class lcs
{

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int lcs( char[] X, char[] Y, int m, int n )
{
if (m == 0 || n == 0)
return 0;
if (X[m-1] == Y[n-1])
return 1 + lcs(X, Y, m-1, n-1);
else
return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
}


int max(int a, int b)
{
return (a > b)? a : b;
}

public static void main(String[] args)
{ Scanner sc=new Scanner(System.in);
lcs ob = new lcs();
String s1 = sc.nextLine();
String s2 = sc.nextLine();

char[] X=s1.toCharArray();
char[] Y=s2.toCharArray();
int m = X.length;
int n = Y.length;

System.out.println("Length of LCS is" + " " +
ob.lcs( X, Y, m, n ) );

sc.close();
}

}
Binary file added sort/selection_sort/c++/a.out
Binary file not shown.
37 changes: 37 additions & 0 deletions sort/selection_sort/c++/selectionsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<iostream>
using namespace std;

int main()
{
int n,i,j,index;
long long a[100000],small;
cin>>n;

for(i=0;i<n;i++)
cin>>a[i];



for(i=0;i<n;i++)
{ small=a[i];
for(j=i+1;j<n;j++)
{
if(a[j]<=small)
{
small=a[j];
index=j;
}
}
a[index]=a[i];
a[i]=small;

}


for(i=0;i<n;i++)
cout<<a[i]<<' ';

return 0;

}