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

📄 dw.cpp

📁 可用于增加
💻 CPP
字号:
#include<iostream>
#include<string>
using namespace std;

struct line
{
	char a[80];
	line* next;
};
line* head;
line* p;
line* last;


void inp()     //input lines
{
   last=head;
   
   int i=0;   
   do
   {
	  
	   p=new(line);
	   i=0;
	   do{
	      cin.get(p->a[i++]);
	   }while(p->a[i-1]!='\n');    
	   
	   last->next=p;
	   last=p;
   }while(p->a[0]!='\n');
    p->next=head->next;     

}
 
void del(int n)
{
	line* q;
	p=head;
	for(int i=0;i<n-1;i++)
	{
		p=p->next;
	}
	q=p->next;
	p->next=q->next;
	delete q;

}

void ins(int n)
{
	char ch;
	int i=0;
	line *q;
	p=head;

	for(i=0;i<n;i++)
	{
		p=p->next;
	}
	cout<<"Please input the new lines\n";
	q=new(line);
	i=0;
    ch=cin.get();
	do{
		cin.get(q->a[i++]);
	
	}while(q->a[i-1]!='\n');
    while(q->a[0]!='\n')
	{
	    i=0;
		q->next=p->next;
		p->next=q;
		p=p->next;
		q=new(line);
	
		do{
		cin.get(q->a[i++]);
		}while(q->a[i-1]!='\n');
	}delete q;


}

void show()
{
	p=head->next;
	while(p->next!=head->next)
	{
	    int i=0;
		do{
        cout<<p->a[i++];
	    
		}while(p->a[i-1]!='\n');
		p=p->next;
	}
}

/*void pickup(int n)
{
	p=head;
	for(int i=0;i<n;i++)
	{
		p=p->next;
	}
	cout<<p->a;
}
*/
void revise(int n)
{
	char ch;
	p=head;
	for(int i=0;i<n;i++)
	{
		p=p->next;
	}
	int j=0;
	cout<<"Please input the new line\n";
	ch=cin.get();
	do{
		cin.get(p->a[j++]);
	}while(p->a[j-1]!='\n');
}
void main()
{
	int n;
	head=new(line);
	cout<<"Please input the lines\n";
	inp();
	char change;
	cout<<"Please input your order\n";
	cin>>change;
	while(change!='q')
	{switch(change)
	{
	   case 'd': cout<<"Please input the line you want to delete\n";
               cin>>n;
			   del(n);
			   show();break;
	   case 'i': cout<<"Please input the line you want to insert after\n";
		       cin>>n;
			   ins(n);
			   show();break;
	   case 'r': cout<<"Please input the line you want to revise\n";
		       cin>>n;
			   revise(n);
			   show();break;
	   
	
	};
	cout<<"Please input your order";
	cin>>change;
	}
}

⌨️ 快捷键说明

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