test02_1.cpp

来自「该包是数据结构的实验软件,来源于合肥工业大学人工智能与数据挖掘实验室,用来实现数」· C++ 代码 · 共 46 行

CPP
46
字号
// test02_1}
#include "linklist.h"


void copy1(link l,link &l1)
{
	link p,r,s;
	p=l->next;
	l1=(link)malloc(sizeof(struct node));
	r=l1;
	while (p!=NULL){
		s=(link)malloc(sizeof(struct node));
		s->data=p->data;
		r->next=s;
		r=s;
		p=p->next;
	}
	r->next=NULL;
}

void copy2(link l,link &l1)
{
	if (l!=NULL){
		l1=(link)malloc(sizeof(struct node));
		l1->data=l->data;
		copy2(l->next,l1->next);
	}else l1=NULL;
}


void main()
{
	link l,l1,l2;
	load_hsllist(l); 
	comput_sllist_card(l,50,100); 
	disp_hsllist("Sllist",l);
	getch();
	copy1(l,l1);
	comput_sllist_card(l1,50,250); 
	disp_hsllist("copy1",l1);
	getch();
	copy2(l,l2);
	comput_sllist_card(l2,50,400); 
	disp_hsllist("copy2",l2);
	getch();
}

⌨️ 快捷键说明

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