标签:style blog color ar 2014 div sp log c
// reverselink.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" struct Node{ int num; struct Node*next; }; typedef struct Node Node; Node * createLink(){ Node *head=NULL,*urn,*tail; int data; cin>>data; while(data>0){ urn=(Node*)malloc(sizeof(Node)); urn->num=data; if(head==NULL) tail=head=urn; else{ tail->next=urn; tail=tail->next; } cin>>data; } if(head!=NULL) tail->next=NULL; return head; } void printNode(Node*head){ Node *p=head; while(p!=NULL){ cout<<p->num<<" "; p=p->next; } return; } int _tmain(int argc, _TCHAR* argv[]) { cout<<"Enter the numbers:"<<endl; Node *head=createLink(); int k=2; stack<Node*> ss; int i; Node *la=NULL,*tail=NULL,*lb=head; while(lb!=NULL){ i=0; Node *top; top=lb; while(lb!=NULL&&i<k){ ss.push(lb); lb=lb->next; i++; } if(i==k){ while(!ss.empty()){ if(la==NULL) la=tail=ss.top(); else{ tail->next=ss.top(); tail=tail->next; } ss.pop(); } if(lb==NULL) tail->next=NULL; } else{ tail->next=top; } } head=la; printNode(head); getchar(); getchar(); return 0; }
标签:style blog color ar 2014 div sp log c
原文地址:http://www.cnblogs.com/593213556wuyubao/p/3976658.html