实验群体类和群体数据吕恩在Word文档下载推荐.docx

上传人:b****3 文档编号:8224266 上传时间:2023-05-10 格式:DOCX 页数:24 大小:39.25KB
下载 相关 举报
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第1页
第1页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第2页
第2页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第3页
第3页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第4页
第4页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第5页
第5页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第6页
第6页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第7页
第7页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第8页
第8页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第9页
第9页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第10页
第10页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第11页
第11页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第12页
第12页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第13页
第13页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第14页
第14页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第15页
第15页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第16页
第16页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第17页
第17页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第18页
第18页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第19页
第19页 / 共24页
实验群体类和群体数据吕恩在Word文档下载推荐.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

实验群体类和群体数据吕恩在Word文档下载推荐.docx

《实验群体类和群体数据吕恩在Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《实验群体类和群体数据吕恩在Word文档下载推荐.docx(24页珍藏版)》请在冰点文库上搜索。

实验群体类和群体数据吕恩在Word文档下载推荐.docx

*next;

//指向后继节点的指针

public:

Tdata;

//数据域

Node(constT&

item,Node<

*ptrnext=NULL);

voidInsertAfter(Node<

*p);

*DeleteAfter(void);

*NextNode(void)const;

};

:

*ptrnext):

data(item),next(ptrnext)

{}

*Node<

NextNode(void)const

returnnext;

}

voidNode<

InsertAfter(Node<

*p)

p->

next=next;

//p节点指针域指向当前节点的后继节点

next=p;

//当前节点的指针域指向p

DeleteAfter(void)

*tempPtr=next;

//将欲删除的节点地址存储到tempPtr中

if(next==NULL)//如果当前节点没有后继节点,则返回NULL

returnNULL;

next=tempPtr->

next;

//使当前节点的指针域指向tempPtr的后继节点

returntempPtr;

//返回被删除的节点的地址

#endif//NODE_CLASS

//Node.h

#ifndefNODE_LIBRARY

#defineNODE_LIBRARY

#include<

iostream>

cstdlib>

#include"

9_5.h"

usingnamespacestd;

*GetNode(constT&

*nextPtr=NULL)

*newNode;

newNode=newNode<

(item,nextPtr);

if(newNode==NULL)//如果分配内存失败,程序中止

cerr<

<

"

Memoryallocationfailure!

endl;

exit

(1);

returnnewNode;

enumAppendNewline{noNewline,addNewline};

voidPrintList(Node<

*head,AppendNewlineaddnl=noNewline)

*currPtr=head;

while(currPtr!

=NULL)

if(addnl==addNewline)

cout<

currPtr->

data<

else

;

currPtr=currPtr->

NextNode();

intFind(Node<

*head,T&

*&

prevPtr)

//从第一个结点开始遍历

prevPtr=NULL;

if(currPtr->

data==item)

return1;

prevPtr=currPtr;

//记录下当前结点的地址

return0;

//找不到时

voidInsertFront(Node<

head,Titem)

head=GetNode(item,head);

voidInsertRear(Node<

head,constT&

item)

*newNode,*currPtr=head;

if(currPtr==NULL)

InsertFront(head,item);

while(currPtr->

NextNode()!

newNode=GetNode(item);

InsertAfter(newNode);

voidDeleteFront(Node<

head)

*p=head;

//取得将被删除的结点的地址

if(head!

=NULL)//确认链表不空

head=head->

//将表头指针head移向第二个结点

deletep;

//删除原第一个结点

voidDelete(Node<

head,Tkey)

*currPtr=head,*prevPtr=NULL;

return;

=NULL&

&

data!

=key)

//currPtr前行,prevPtr跟随其后

if(currPtr!

if(prevPtr==NULL)//找到的是链表第一个结点

prevPtr->

DeleteAfter();

deletecurrPtr;

//释放被删除的结点所占的内存空间

voidInsertOrder(Node<

*currPtr,*prevPtr,*newNode;

currPtr=head;

if(item<

data)

break;

if(prevPtr==NULL)//如果插入点在表头

voidClearList(Node<

*currPtr,*nextPtr;

nextPtr=currPtr->

currPtr=nextPtr;

//使指针currPtr指向下一个结点

head=NULL;

//将头结点置为NULL,标志着链表为空

#endif//NODE_LIBRARY

//lab9_1.cpp

node.h"

intmain()

int>

*head=NULL,*prevPtr,*delPtr;

inti,key,item;

for(i=0;

i<

10;

i++)

pleaseinput"

i+1<

numberToinsertaheader:

cin>

>

item;

List:

PrintList(head,noNewline);

请输入一个需要删除的整数:

key;

prevPtr=head;

while(Find(head,key,prevPtr)!

delPtr=prevPtr->

deletedelPtr;

ClearList(head);

运行结果:

pleaseinput1numberToinsertaheader:

1

pleaseinput2numberToinsertaheader:

2

pleaseinput3numberToinsertaheader:

3

pleaseinput4numberToinsertaheader:

4

pleaseinput5numberToinsertaheader:

5

pleaseinput6numberToinsertaheader:

6

pleaseinput7numberToinsertaheader:

7

pleaseinput8numberToinsertaheader:

8

pleaseinput9numberToinsertaheader:

9

pleaseinput10numberToinsertaheader:

10

10987654321

1098765431

2.//link.h

#ifndefLINKEDLIST_CLASS

#defineLINKEDLIST_CLASS

#ifndefNULL

constintNULL=0;

#endif//NULL

classLinkedList

*front,*rear;

*prevPtr,*currPtr;

intsize;

intposition;

*ptrNext=NULL);

voidFreeNode(Node<

voidCopyList(constLinkedList<

L);

LinkedList(void);

LinkedList(constLinkedList<

//拷贝构造函数

~LinkedList(void);

LinkedList<

operator=(constLinkedList<

intListSize(void)const;

//返回链表中元素个数(size)

intListEmpty(void)const;

//size等于0时返回TRUE,否则返回FALSE

voidReset(intpos=0);

voidNext(void);

//使prevPtr和currPtr移动到下一个节点

intEndOfList(void)const;

intCurrentPosition(void)const;

//返回数据成员position

voidInsertFront(constT&

item);

//在表头插入

voidInsertRear(constT&

//在表尾添加

voidInsertAt(constT&

//在当前节点之前插入

voidInsertAfter(constT&

//在当前节点之后插入

TDeleteFront(void);

//删除头节点

voidDeleteAt(void);

//删除当前节点

T&

Data(void);

voidClearList(void);

*LinkedList<

GetNode(constT&

item,

*ptrNext)

*p;

p=newNode<

(item,ptrNext);

if(p==NULL)

\n"

returnp;

voidLinkedList<

FreeNode(Node<

CopyList(constLinkedList<

L)

*p=L.front;

intpos;

while(p!

InsertRear(p->

data);

p=p->

if(position==-1)

currPtr=front;

for(pos=0;

pos!

=position;

pos++)

LinkedList(void):

front(NULL),rear(NULL),

prevPtr(NULL),currPtr(NULL),size(0),position(-1)

front=rear=NULL;

prevPtr=currPtr=NULL;

size=0;

position=-1;

CopyList(L);

ClearList(void)

*currPosition,*nextPosition;

currPosition=front;

while(currPosition!

nextPosition=currPosition->

FreeNode(currPosition);

currPosition=nextPosition;

//移动到下一结点

~LinkedList(void)

ClearList();

operator=

(constLinkedList<

if(this==&

L)//不能将链表赋值给它自身

return*this;

intLinkedList<

ListSize(void)const

returnsize;

ListEmpty(void)const

returnsize==0;

Next(void)

position++;

EndOfList(void)const

returncurrPtr==NULL;

CurrentPosition(void)const

returnposition;

Reset(intpos)

intstartPos;

if(front==NULL)

if(pos<

0||pos>

size-1)

Reset:

Invalidlistposition:

pos

if(pos==0)

position=0;

currPtr=front->

prevPtr=front;

startPos=1;

for(position=startPos;

position!

=pos;

position++)

Data(void)

if(size==0||currPtr==NULL)

Data:

invalidreference!

returncurrPtr->

data;

InsertFront(constT&

if(front!

Reset();

InsertAt(item);

InsertRear(constT&

prevPtr=rear;

//创建新结点

if(rear==NULL)//如果表空则插入在表头

front=rear=newNode;

rear->

rear=newNode;

currPtr=rear;

position=size;

size++;

InsertAt(constT&

if(prevPtr==NULL)

newNode=GetNode(item,front);

front=newNode;

if(prevPtr==rear)

currPtr=newNode;

InsertAfter(constT&

p=GetNode(item);

if(front==NULL)//向空表中插入

front=currPtr=rear=p;

currPtr=prevPtr;

InsertAfter(p);

if(currPtr==rear)

rear=p;

currPtr=p;

//使链表长度增值

TLinkedList<

DeleteFront(void)

Titem;

Invaliddeletion!

item=currPtr->

DeleteAt();

returnitem;

DeleteAt(void)

p=front;

front=front->

p=prevPtr->

if(p==

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2