sir,
yesterday i tried to written a programme which takes some(any number) names as input and sort in ascending order.
Syntax is correct and programme works partially. really i don't know how to create dynamic array of pointers in C++. would you please help me.....
i am attaching my code with this post. please take look
Code:#include<iostream.h> #include<conio.h> void main() { clrscr(); //*a = new (int*)[SIZE]; //for(int j=0; j<SIZE; j++) //a[SIZE] = new int[SIZE]; int size,p,m,n,i,j,k; cout<<"enter the no of names: "; cin>>size; char **pt=new char*[size]; char *ptr; cout<<"\nEnter names: "; for(i=0;i<size;i++) cin>>*(pt+i); for(i=0;i<size-1;i++) { p=0; for(j=0;j<size-1-i;j++) for(k=0;;k++) { if(*(pt+p)+k=='\0') { p=j; break; } else if(*(pt+j+1)+k=='\0') break; m=*(*(pt+p)+k); n=*(*(pt+j+1)+k); if(m==n) continue; else if(n>m) { p=j+1; break; } else break; } ptr=*(pt+p); *(pt+p)=*(pt+size-i); *(pt+size-i)=ptr; } for(i=0;i<size;i++) cout<<*(pt+i); delete []pt; getch(); }



LinkBack URL
About LinkBacks


