Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# MCA_Lab12_STRING
This repo is included in DO_SCM_Lab Experiment 4's exercise
86 changes: 86 additions & 0 deletions src/pkg1/S500097692.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import java.util.Arrays;

public class S500097692 {
public static void main(String[] args) {
int[] arr=new int[]{10,9,8,7,6};
int[] ans=sort(arr);
System.out.println(Arrays.toString(ans));
sort_in_place(arr,0, arr.length);
System.out.println(Arrays.toString(arr));
}
static int[] sort(int[] arr){
if(arr.length==1){
return arr;
}
int mid=arr.length/2;
int[] left=sort(Arrays.copyOfRange(arr,0,mid));
int[] right=sort(Arrays.copyOfRange(arr,mid,arr.length));
return merge(left,right);
}
static int[] merge(int[] first,int[] second){
int[] mix=new int[first.length+second.length];
int i=0,j=0,k=0;
while(i<first.length && j<second.length){
if(first[i]<second[j]){
mix[k]=first[i];
i++;
}else{
mix[k]=second[j];
j++;
}
k++;
}
// it may be possible that some elements of either arrays are left out, so we need to add then into the mix array
while(i<first.length){
mix[k]=first[i];
i++;
k++;
}
while(j<second.length){
mix[k]=second[j];
j++;
k++;
}
return mix;
}


static void sort_in_place(int[] arr,int s,int e){
if(e-s ==1){
return;
}
int mid=s+(e-s)/2;
sort_in_place(arr,0,mid);
sort_in_place(arr,mid,e);
merge_in_place(arr,s,mid,e);
}
static void merge_in_place(int[] arr, int s, int m, int e){
int[] mix=new int[e-s];
int i=s,j=m,k=0;
while(i<m && j<e){
if(arr[i]<arr[j]){
mix[k]=arr[i];
i++;
}else{
mix[k]=arr[j];
j++;
}
k++;
}
// it may be possible that some elements of either arrays are left out, so we need to add then into the mix array
while(i<m){
mix[k]=arr[i];
i++;
k++;
}
while(j<e){
mix[k]=arr[j];
j++;
k++;
}

for (int l=0;l<mix.length;l++){
arr[s+l]=mix[l];
}
}
}
14 changes: 14 additions & 0 deletions src/pkg1/flippingimage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class flippingimage{
public int[][] flipAndInvertImage(int[][] image) {
for (int[] row : image) {
// reversing the array
for(int i=0;i<(image[0].length+1)/2;i++){
// swaps the element(reversing)
int temp=row[i]^1;
row[i]=row[image[0].length-i-1]^1;
row[image[0].length-i-1]=temp;
}
}
return image;
}
}