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

📄 bob.cpp

📁 实现了一个链表的逆转,全部过程在一个链表内完成!
💻 CPP
字号:
#include <iostream.h>
#include <stdio.h>
struct list
{
	int data;
	struct list *next;
};
list *create()
{
   struct list *h,*t,*p;
   int a;
   h=new list;
   t=h;
   t->next=NULL;
   cout<<"请输入数据(输入0结束并开始逆转你输入的数据):";
   cin>>a;
   while(a!=0)
   {
	   p=new list;
	   p->data=a;
	   t->next=p;
	   t=p;
       cout<<"请输入数据(输入0结束并开始逆转你输入的数据):";
       cin>>a;
   }
   t->next=NULL;
   return h;
}
list *change(list *h)
{
   list *p,*p1,*p2;
   p=h;
   p1=h->next;
      while(p1->next!=NULL)
   {  
	  p2=p1->next;
      p1->next=p2->next;
	  p2->next=h->next;
	  h->next=p2;
   }
   return h;
}
void main()
{
	struct list *head,*p,*p1;
	char c;
	do{
	   head=create();
	   p=head->next;
	   cout<<"你输入的数据为:";
       while(p!=NULL)
	   {
	     cout<<p->data<<" ";
         p=p->next;
	   }
       cout<<endl;
       head=change(head);
       cout<<"逆转后的数据为:";
       p1=head->next;
       while(p1!=NULL)
	   {
	     cout<<p1->data<<" ";
	     p1=p1->next;
	   }
       cout<<endl;
	   cout<<"退出程序?[Y/N]:";
	   cin>>c;
	   }while(c=='n'||c=='N');
}

⌨️ 快捷键说明

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