诺西的题,跪求大家帮忙看看,全英文的一道编程题,谢谢,通宵求助
Given a head pointer pointing to a linked list, please write a function that sort the list in increasing order.
Typedef struct S_Node
{
int data;
struct S_Node *next;
}Node;
Node*sort_link_list_increasing_order(Node *header);
Ugly numbers are numbers whose only prime(质因数) factors are 2,3or 5.The sequence 1,2,3,4,5,6,8,9,10,12,15,…shows the first 11ugly numbers. By convention,1 is included.
Write a time efficient program to find and print the 1500’th(打印第1500个数) ugly number
[解决办法]
Node*sort_link_list_increasing_order(Node *header);
{
Node* p = header;
int nCount = 0;
int num =1;
int temp =num;
while(1) {
if(1 == temp){
p = p->next;p->data = num;
nCount ++;num++;temp=num;continue; }
if(nCount == 1500){
cout<<"finish”;return header; }
if(0 == temp%2){
temp = temp >>1;continue; }
if(0 == temp%3){
temp =temp/3;continue; }
if(0 == temp%5){
temp=temp/5;continue; }
num ++;
temp =num;
}
}
low = 1; high = n - 1;下标从0开始
prod = S[low] * S[high];
while(low <= high){
if(S[low]*S[high] <= S[n-1]){
++low;
}else{
if(S[low]*S[high] < prod){
prod = S[low]*S[high];
}
--high;
}
}
return prod;