| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include <stdio.h> 
#include <stdlib.h> 
 
 
struct Node { 
        int Date; 
        struct Node *next; 
}; 
 
 
 
typedef struct Node *List; 
 
List ReadInput(); 
void PrintList(List L); 
void K_Reverse(List L, int K);  
 
List ReadInput() 
{ 
        List head,tail,p; 
        head=(List)malloc(sizeof(struct Node)); 
        head->next=NULL; 
        tail=head; 
        int i,n; 
        scanf("%d",&n);//有多少个数  
                 
         
        for(i=0;i<n;i++)//输入这几个数  
        { 
                p=(List)malloc(sizeof(struct Node)); 
                scanf("%d",&p->Date); 
                p->next=NULL; 
                tail->next=p; 
                tail=p; 
        } 
        return head;//有人说不用有人说要,我也不知道返回head干嘛  
                 
                 
} 
void K_Reserve(List L,int k) 
{ 
                List head,tail,old,temp,cur; 
                List p; 
                List newone;  
                int count,cishu,j; 
                head=(struct Node*)malloc(sizeof(struct Node)); 
                tail=NULL; 
                while(p) 
                { 
                        count++; 
                        p=p->next; 
                } 
                cishu=count/k; 
                if(k==1||cishu==0) 
                { 
                        return; 
                } 
                else 
                { 
                        newone=L->next; 
                        old=newone->next; 
                        tail=L; 
                        while(cishu>0) 
                        { 
                                j=1; 
                                cur=newone; 
                                while(j<k) 
                                { 
                                         
                                        newone=head->next; 
                                        old=newone->next; 
                                        temp=old->next; 
                                        head=head->next; 
                                        j++; 
                                } 
                                cur->next=newone; 
                                tail->next=old; 
                                tail=cur; 
                                cishu--; 
                                if(old=NULL) 
                                { 
                                        break; 
                                } 
                                else 
                                { 
                                        newone=old; 
                                        old=old->next; 
                                } 
                        } 
                } 
} 
 
void PrintList(List L) 
{ 
        List p; 
        p=L->next; 
        while(p)//打印逆置后的数  
        { 
                printf("%d",&p->Date); 
                p=p->next; 
        } 
} 
int main() 
{ 
        List L; 
        int k; 
         
        L=ReadInput(); 
        scanf("%d",&k);//每多少个数逆置  
        K_Reserve(L,k); 
        PrintList(L); 
         
        return 0; 
 }  |   
 
 
 
 |