Sunday, February 10, 2019

Write a program for performing a card shuffle of a list of 2n elements. A card shuffle is a permutation where a list A is cut into two sub lists, A1 and A2, where A1 is the first half of A and A2 is the second half of A, and then these two sublists are combined into a single list again by taking the first element in A1, then the first element in A2, followed by the second element in A1, the second element in A2, and so on. Here A1 and A2 are both of size n Example : If the input list is A = {7, 10, 1, 6, 24, 15, 9, 4, 2, 20}, then it is cut into two sub lists A1 = {7, 10, 1, 6, 24} and A2 = {15, 9, 4, 2, 20}, then the output is B = {7, 15, 10, 9, 1, 4, 6, 2, 24, 20}

#include<stdio.h>
main()
{
int arr[10],arr2[5],arr3[5],i,j;
printf("Enter A Elemnts:");
for(i=0;i<10;i++)
{
scanf("%d",&arr[i]);
}

for(i=0;i<5;i++)
{
arr2[i]=arr[i];
}
printf("A1=");
for(i=0;i<5;i++)
{
printf("%d\t",arr2[i]);
}

for(i=5;i<10;i++)
{
arr3[i]=arr[i];
}
printf("\n");
printf("A2=");
for(i=5;i<10;i++)
{
printf("%d\t",arr3[i]);
}

printf("\nB=");
for(i=0,j=5;i<5,j<10;i++,j++)
{
printf("%d\t%d\t",arr2[i],arr3[j]);
}
}

No comments:

Post a Comment

Manhattan Distance Heuristic

#include<stdio.h> #include<stdlib.h> struct node{  int arr[10][10];  int i,j;  int md; }; int a[10][10]; struct node*...