using namespace std;
class Cstring
{
char *ptr[50];
int length;
public:
Cstring(int l)
{
length=l;
for(int i=0;i<length;i++)
{
ptr[i]=(char*)malloc(sizeof(char)*20);
}
}
void getarray()
{
cout<<"Enter the elements of array"<<endl;
for(int i=0;i<length;i++)
{
cin>>ptr[i];
}
}
void sort()
{
cout<<"hello\n";
char* temp;
for(int i=0;i<length-1;i++)
{
for(int j=0;j<10;j++)
{
if(((*(*(ptr+i)+j))=='\0')||((*(*(ptr+i+1)+j))=='\0'))
break;
if((*(*(ptr+i)+j))>(*(*(ptr+i+1)+j)))
{
temp=*(ptr+i);
*(ptr+i)=*(ptr+i+1);
*(ptr+i+1)=temp;
}
if((*(*(ptr+i)+j))!=(*(*(ptr+i+1)+j)))
break;
}
}
}
void show()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl;
for(int i=0;i<length;i++)
{
cout<<ptr[i]<<endl;
}
}
};
template<class T>
class bubble1
{
T a[20];
int length;
public:
void sort()
{
T temp;
for(int i=0;i<length;i++)
{
for(int j=0;j<length-i-1;j++)
{
if(a[j+1]<a[j])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
void show()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl;
for(int i=0;i<length;i++)
{
cout<<a[i]<<endl;
}
}
void getarray()
{
cout<<"Enter the elements of array"<<endl;
for(int i=0;i<length;i++)
{
cin>>a[i];
}
}
};
int main()
{
int len;
cout<<"Enter the length of array";
cin>>len;
Cstring b1(len);
b1.getarray();
b1.sort();
b1.show();
return 0;
}
Comments