list.cpp

来自「虚基类的实现」· C++ 代码 · 共 75 行

CPP
75
字号
// List.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include <iostream>
using namespace std;

#include "Node.h"
#include "StringObject.h"
#include "list1.h"

int main(void)
{
	Node *P1;
	StringObject *p;
	list list1,list2,list3;
	char *a[5]={"dog","cat","bear","sheep","ox"},*sp="cat";
	int i;

	
	for(i=0;i<5;i++)
	{
		p=new StringObject(a[i]);
		P1=list1.CreatNode();         
		P1->Linkinfo(p);             
		list1.InsertFront(P1);        

		
		p=new StringObject(a[i]);
		P1=list2.CreatNode();
		P1->Linkinfo(p);
		list2.InsertRear(P1);
	}

	list1.PrintList();
	cout<<"list1长度:"<<list1.Length()<<endl;
	list2.PrintList();
	cout<<"要求删除的字符串\"cat\""<<endl;
	
	p=new StringObject(sp);
	P1=list1.Find(*p);
	delete p;
	if(P1!=NULL)
	{
		cout<<"删除cat"<<endl;
		P1=list1.DeleteNode(P1);
		delete P1;
		list1.PrintList();
		cout<<"list1长度:"<<list1.Length()<<endl;
	}
	else
	{
		cout<<"未找到"<<endl;
	}

	cout<<"清空list1"<<endl;
	list1.MakeEmpty();
	list1.PrintList();

	for(i=0;i<5;i++)
	{
		p=new StringObject(a[i]);
		P1=list3.CreatNode();
		P1->Linkinfo(p);
		list3.InsertOrder(P1);
	}

	list3.PrintList();
	cout<<"程序结束"<<endl;

	return 0;
}

⌨️ 快捷键说明

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