Dear all, I am new here and I am new to work with C/C++. I am posting my code here. it has no error. but showing code.exe has stopped working. I am using code blocks. I will be really grateful if anyone can give any solution. Thanks in advance.
Code:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
const int t=2;//12;
const int n=6;//195;
const int l=3;
const int k=4;//n-l+1//need to change
int i=1;
//int j;
int *nextvertex(int s[])
{
int j;
if(i<l)
{
s[i+1] = 1;
i=i+1;
return s;
}
else
{
for(j=l;j>=1;j--)
{
if(s[j]<k)
{
s[j]=s[j]+1;
i=j;
return s;
}
}
}
i=0;
return s;
}
int *bypass(int s[])
{ int j;
for(j=i;j>=1;j--)
{
if(s[j]<k)
{
s[j]=s[j]+1;
i=j;
return s;
}
}
i=0;
return s;
}
int totaldistance(int prefix[], int dna[][n])
{
// int s[5]={1,1,1,1,1};
int sum=0;
//int s1=1;
//s=&s1;
int ls;
ls=sizeof(prefix);
cout<<"ls="<<ls<<"\n";
int x,y,a,td=0;
for(x=0;x<t;x++)
{ int dist=0;
for(y=0;y<n-ls+1;y++)
{
int a=0, c=0;
for(int z=y;z<y+ls;z++)
{
int w=dna[x][z];
int b=prefix[a];
if(dna[x][z]!=prefix[a])
{
c+=1;
}
a++;
/*if(s[0]!=dna[x][y])
{
a++;
}
cout<<a<<" ";
td=td+a;*/
}
if(c<dist||y==0)
{
dist=c;
}
}
sum=sum+dist;
}
cout<<"\n";
cout<<"total distance:"<<sum<<"\n";
return sum;
}
int *branchandboundmediansearch(int dna[][n])
{
int s1=1;
int *s=new int [l];
s=&s1;
// int *s=new int [l];
int *prefix=new int [i];
// prefix=new int[i];
int word[8];
int bestword[8];
int bestdis=16;//96;
int j, optdis, x, y;
while(i>0)
{
if(i<l)
{
for(x=0;x<i;x++)
{
prefix[x]=s[x];
cout<<"prefix:"<<prefix[x];
}
cout<<"\n";
optdis= totaldistance(prefix,dna);
if(optdis>bestdis)
{
s=bypass(s);
}
else
{
s=nextvertex(s);
}
}
else
{
for(x=0;x<l;x++)
{
word[x]=s[x];
}
if(totaldistance(word,dna)<bestdis)
{
bestdis=totaldistance(word,dna);
for(x=0;x<l;x++)
{
bestword[x]=word[x];
}
}
s=nextvertex(s);
}
}
return bestword;
delete [] s;
delete [] prefix;
}
main()
{
int x,y,opd;
string str;
int arr[12], dna[t][n];
// int *l_mer1[8];
int *l_mer;
// int *l_mer=l_mer1;
// char finall_mer1[8];
// char finall_mer=finall_mer1;
//char *finall_mer=finall_mer1;
// int s1=1;
//int *s=new int [l];
//=new int[l];
// s=&s1;
/* for(x=0;x<l;x++)
{
cout<<"s:"<<s[x]<<" ";
}
cout<<"\n";*/
//out<<s;
//nt *s2;
char finall_mer[l];
//2=nextvertex(s);
//cout<<s2;
/* ifstream myfile ("E:/Codeblocks codes/C++ codes/bbms/input.txt");
if (myfile.is_open())
{
while ( !myfile.eof() )
{
myfile>>str;
cout << str << "\n";
}
myfile.close();
}*/
cin>>str;
// int s[11]={1,1,1,1,1,1,1,1,1,1,1};
// cout<<str;
//strcpy(str1,str);
for(x=0;x<12;x++)
{
if(str[x]=='A')
{
arr[x]=1;
//cout<<arr[i]<<" ";
}
else if(str[x]=='C')
{
arr[x]=2;
//cout<<arr[i]<<" ";
}
else if(str[x]=='G')
{
arr[x]=3;
//cout<<arr[i]<<" ";
}
else
{
arr[x]=4;
//cout<<arr[i]<<" ";
}
}
cout<<"\n ";
for(x=0;x<12;x++)
{
cout<<arr[x];
}
cout<<"\n";
int a=0;
while(a<12)//a: for counting 1D array
{
for(x=0;x<t;x++)
{
for(y=0;y<n;y++)
{
dna[x][y]=arr[a];
a++;
}
}
}
for(x=0;x<t;x++)
{
for(y=0;y<n;y++)
{
cout<<dna[x][y]<<" ";
//a++;
}
cout<<"\n";
}
// opd=totaldistance(s,dna);
//cout<<"\n"<<opd;
//s=nextvertex(s);
//cout<<s;
l_mer=branchandboundmediansearch(dna);
for(x=0;x<l;x++)
{
if(l_mer[x]==1)
{
finall_mer[x]='A';
cout<<finall_mer[x]<<"\n";
//cout<<arr[i]<<" ";
}
else if(l_mer[x]==2)
{
finall_mer[x]='C';
cout<<finall_mer[x]<<"\n";
//cout<<arr[i]<<" ";
}
else if(l_mer[x]==3)
{
finall_mer[x]='G';
cout<<finall_mer[x]<<"\n";
//cout<<arr[i]<<" ";
}
else
{
finall_mer[x]='T';
cout<<finall_mer[x]<<"\n";
//cout<<arr[i]<<" ";
}
}
// cout<<"\n"<<finall_mer;*/
// delete [] prefix;
}