⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 逆转.cpp

📁 发射系下飞行器九参数计算
💻 CPP
字号:
#include"iostream.h"

struct node
{  int d;
   struct node *next;
};

void  main()
{
   int x,n=0;
   struct node *head,*p,*q,*r;
   p=new(struct node);
   head=p;
   head->d=n;
   head->next=NULL;

   cin>>x;                 //建立链表
   while(x!=0)
   {   p=new(struct node) ;
       p->d=x;
	   p->next=NULL;
	   if(head->next==NULL)  head->next=p;
	   else q->next=p;
       q=p;
	   ++n;
	   cin>>x;
	 
   }
   
   q->next=head;
   head->d=n;
   cout<<"Before reversing:";
   p=head->next ;          //显示链表
   while(p!=head)
   {  cout<<"  "<<p->d;
      p=p->next;
   }
   cout<<endl;

   p=head;               //逆转链表
   q=p->next;
   r=q->next;
   while(q!=head )
   {   q->next=p;
       p=q;
	   q=r;
	   r=r->next;
	  
   }
   head->next =p;

   cout<<"After reversing: ";   //显示逆转后的链表
   p=head->next ;
   while(p!=head)
   {   cout<<"  "<<p->d;
      p=p->next;
   }
   cout<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -