Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Seek the report of data structure course design.
Seek the report of data structure course design.
//class CNode.h

#ifndef __CNODE_H__

# Definition __CNODE_H__

# include & ltiostream & gt

Use namespace std

Structure ST data//date of birth structure

{

int m _ nYear

int m _ nMonth

int m _ nDay

};

Structural stress results//Five-course hierarchical structure

{

double m _ d subject _ 1; //Change the grade name yourself

double m _ d subject _ 2;

double m _ d subject _ 3;

double m _ d subject _ 4;

double m _ d subject _ 5;

};

Struct stStudent // declares the structure of student information.

{

String m _ strNumber// student ID

The name of the string m _ strName//

Char m _ chSex// gender

Struct stData m _ stData// Date of birth

String m _ strAppearance///political views

Struct stResult m _ stResult// Five course scores

};

Typedef class CNode

{

Private:

struct stStudent m _ stStudent

CNode * m _ Next

Public:

CNode(); //constructor

~ CNode(); //Destructor

void SetNodeData(); //Set the function members of the node content

ST student GetNodeData(); //Get the function members of the node content.

void SetNodeNext(CNode * _ Next); //Set the function member of the next pointer of the node.

void ShowNodeData(); //Function members that output node contents

CNode * GetNodeNext(); //Get the function member of the next pointer of the node.

} LinkNode

#endif

//class CLinkList

#ifndef __CLINKLIST_H__

#define __CLINKLIST_H__

# contains "CNode.h"

Typedef class CLinkList

{

Private:

The head pointer of LinkNode * m _ Head// linked list.

The head node of LinkNode m _ Node// linked list.

Public:

clink list(); //constructor

~ clink list(); //Destructor

void create list(); //Initialize the function members of the linked list

LinkNode * GetListNode(int _ nIndex); //Find the member function of the specified bit node by position.

void insert list(int _ nIndex); //Insert the member function of the node.

void delete list(int _ nIndex); //Delete the member function of a node.

LinkNode * GetHeadList(); //Get the member function of the head pointer

void SetListData(int _ nIndex); //Set the member function of the node value in the linked list.

void ShowListData(int _ nIndex); //This is a function member of a node value in the real linked list.

void DestroyList(int _ nIndex); //Destroy the member function of the linked list after a certain position.

void ShowList(); //Displays the member functions of the linked list.

} Linked list;

#endif

//class CLinkList

# contains "CLinkList.h"

# contains "CNode.h"

CLinkList::CLinkList()

{

Cout & lt& lt "This is a constructor"

M _ Head = & ampm _ Node// The head pointer of the linked list points to the head node.

M _ node. SetNodeNext(NULL); //Set the next pointer of the head node to NULL.

}

CLinkList::~CLinkList()

{

Cout & lt& lt "This is a destructor"

}

Void CLinkList::CreateList() // Create a linked list by appending backward, and enter 0 to exit.

{

int nTemp = 0; //Define a temporary variable to mark the end of the program.

Cout & lt& lt "Welcome to create a linked list!" & lt& ltendl

CNode * pTemp = NULL// Defines a temporary node pointer for adding a new node.

CNode * pNode = m _ Head// Define a tag pointer, and first call it to point to the head node.

while( 1)

{

PTemp = new LinkNode

Cout & lt& lt "Please enter the content of the next node!" & lt& ltendl

pTemp-& gt; SetNodeData(); //Set the contents of the nodes in the linked list.

Cout & lt& lt "If you want to continue to enter the information of the next student, please enter 1, otherwise enter 0" < < endl

CIN & gt; & gtnTemp

if ('0' == nTemp)

{

Break;

}

pNode-& gt; SetNodeNext(pTemp); //Let Next at the end of the chain point to the newly created node.

PNode = pTemp// Move the closing element back.

}

Cout & lt& lt "End of creating linked list"

}

LinkNode * clink list::GetListNode(int _ nIndex)

{

Cout & lt& lt "This is a member function to find the specified node by location"

link node * pNode = m _ Head-& gt; GetNodeNext(); //Define a temporary node pointer to initialize the node pointing to the head.

int Temp = 0; //Define a temporary variable to mark the number of selected nodes.

If(- 1 == _nIndex) // returns the head node (that is, the head pointer).

{

Return m _ Head

}

if(_ nIndex & lt; -1)/_ nindex control conditions

{

Cout & lt& lt "You are in the wrong position!" & lt& ltendl

Returns 0;

}

And (pNode! = empty)

{

if(_nIndex == Temp)

{

Return to pNode

}

pNode = pNode-& gt; GetNodeNext(); //The temporary node moves backward.

++temperature;

}

Returns pNode// NULL if the node cannot be found.

}

void clink list::ShowListData(int _ nIndex);

Voidclinklist:: InsertList (int _ nindex)//Insert the function member of the node.

{

Cout & lt& lt "This is the member function of the inserted node"

LinkNode * pNode = GetListNode(_ nIndex- 1); //Define a pointer to the node class, pointing to the previous pointer where you want to insert it.

LinkNode* pTemp = new CNode// Defines a temporary node pointer for adding a new node.

pTemp-& gt; SetNodeData(); //Set the content of the inserted node.

pTemp-& gt; SetNodeNext(pNode-& gt; GetNodeNext());

pNode-& gt; SetNodeNext(pTemp);

}

void clink list::delete list(int _ nIndex)

{

Cout & lt& lt "This is a member function to delete nodes"

LinkNode * pNode = GetListNode(_ nIndex- 1); //Define a pointer to the node class, pointing to the previous pointer to the location to be deleted.

LinkNode * pTemp = NULL// Defines a temporary node pointer to the node to be deleted.

pTemp = pNode-& gt; GetNodeNext(); //Point pTemp to the node to be deleted.

pNode-& gt; SetNodeNext(pTemp-& gt; GetNodeNext()); //Point the pNode to the node after the node to be deleted.

Delete pTemp// Delete node

pTemp = NULL

}

LinkNode * clink list::GetHeadList()

{

Cout & lt& lt "This is a member function that gets the head pointer."

Return m _ Head

}

void clink list::SetListData(int _ nIndex)

{

Cout & lt& lt "This is a member function that sets the values of nodes in the linked list."

CNode * pNode = GetListNode(_ nIndex); //Defines a pointer to the node class, pointing to the node where the content is to be modified.

pNode-& gt; SetNodeData(); //Modify the content

}

void clink list::ShowListData(int _ nIndex)

{

Cout & lt& lt "This is a member function that displays the values of nodes in the linked list"

CNode * pNode = GetListNode(_ nIndex); //Defines a pointer to the node class, pointing to the node where the content is to be obtained.

pNode-& gt; show nodedata(); //Returns the contents of the node at the required position.

}

void clink list::DestroyList(int _ nIndex)

{

Cout & lt& lt "This is the member function of the linked list after it is destroyed in a certain position"

LinkNode * pTemp = GetListNode(_ nIndex- 1); //Define a node pointer to the node before the location to be destroyed.

link node * pNode = pTemp-& gt; GetNodeNext(); //Define a node pointer to the node of the location to be destroyed.

while(pTemp-& gt; GetNodeNext()! = NULL) // End condition or initial condition of the destruction operation

{

pTemp-& gt; SetNodeNext(pNode-& gt; GetNodeNext()); //Point the next node of the previous node at the location to be destroyed to the next node at the location to be destroyed.

Delete pNode// Destroy node

pNode = pTemp-& gt; GetNodeNext(); //The node that redirects the pNode to the location to be destroyed.

}

}

void CLinkList::ShowList()

{

Cout & lt& lt "This is a member function that displays a linked list"

int nTemp = 0; //Define a temporary integer variable to control the number of inputs.

link node * pTemp = m _ Head-& gt; GetNodeNext(); //Defines a node class pointer to a node with bit 0.

if(NULL == pTemp)

{

Cout & lt& lt "This is an empty chain"

}

while(pTemp! = empty)

{

pTemp-& gt; show nodedata();

++ nTemp;

if(0 = = nTemp % 5 & amp; & ampnTemp! = 0) // Control that only five nodes can be output per line.

{

cout & lt& ltendl

}

pTemp = pTemp-& gt; GetNodeNext();

}

}

//class CNode

# contains "CNode.h"

CNode::CNode() // constructor

{

//m _ ST student = { 0 };

m _ Next = NULL

}

CNode::~CNode() // destructor

{

}

void CNode::SetNodeData()

{

char * p number = new char[30]; //A temporary variable used to receive a string.

char * pName = new char[30];

char * pAppearance = new char[30];

Cout & lt& lt "Student ID:"

CIN & gt; & gtpNumber

m _ ST student . m _ str number = p number;

Cout & lt& lt "Name:"

CIN & gt; & gtpName

m _ stStudent.m _ strName = pName

Cout & lt& lt "Gender:"

CIN & gt; & gtm _ ST student . m _ CHS ex;

Cout & lt& lt "Date of birth:"

cout & lt& lt" m _ stData.m _ nYear " & lt& ltendl

CIN & gt; & gtm _ ST student . m _ stdata . m _ Nye ar;

cout & lt& lt" m _ stData.m _ nMonth " & lt& ltendl

CIN & gt; & gtm _ ST student . m _ stdata . m _ n month;

cout & lt& lt" m _ stData.m _ nDay " & lt& ltendl

CIN & gt; & gtm _ ST student . m _ stdata . m _ nDay;

Cout & lt& lt "Political characteristics:"

CIN & gt; & gtpAppearance

m _ ST student . m _ strap pearance = pap pearance;

Cout & lt& lt "Scores of five courses:"

cout & lt& lt" m _ d subject _ 1:" & lt; & ltendl

CIN & gt; & gtm _ ST student . m _ stresult . m _ d subject _ 1;

cout & lt& lt" m _ d subject _ 2:" & lt; & ltendl

CIN & gt; & gtm _ ST student . m _ stresult . m _ d subject _ 2;

cout & lt& lt" m _ d subject _ 3:" & lt; & ltendl

CIN & gt; & gtm _ ST student . m _ stresult . m _ d subject _ 3;

cout & lt& lt" m _ d subject _ 4:" & lt; & ltendl

CIN & gt; & gtm _ ST student . m _ stresult . m _ d subject _ 4;

cout & lt& lt" m _ d subject _ 5:" & lt; & ltendl

CIN & gt; & gtm _ ST student . m _ stresult . m _ d subject _ 5;

Delete [] p number; //Free memory

PNumber = NULL// pointer is empty.

Delete [] pname; //Free memory

pName = NULL

Delete [] page appearance; //Free memory

pAppearance = NULL

}

Ststudentcnode:: getnodedata ()//Returns the node content (that is, student information).

{

Return to m _ stStudent

}

void CNode::SetNodeNext(CNode * _ Next)

{

m _ Next = _ Next

}

void CNode::ShowNodeData()

{

const char * p number = m _ ST student . m _ strnumber . c _ str(); //A temporary variable used to receive a string.

const char * pName = m _ ST student . m _ strnumber . c _ str();

const char * pAppearance = m _ ST student . m _ strap pearance . c _ str();

Cout & lt& lt "Student ID:"

Cout & lt& lt "Date of birth:"

Cout & lt& lt "Political characteristics:"

cout & lt& lt" m _ d subject _ 1:" & lt; & ltm _ ST student . m _ stresult . m _ d subject _ 1 & lt; & ltendl

cout & lt& lt" m _ d subject _ 2:" & lt; & ltm _ ST student . m _ stresult . m _ d subject _ 2 & lt; & ltendl

cout & lt& lt" m _ d subject _ 3:" & lt; & ltm _ ST student . m _ stresult . m _ d subject _ 3 & lt; & ltendl

cout & lt& lt" m _ d subject _ 4:" & lt; & ltm _ ST student . m _ stresult . m _ d subject _ 4 & lt; & ltendl

cout & lt& lt" m _ d subject _ 5:" & lt; & ltm _ ST student . m _ stresult . m _ d subject _ 5 & lt; & ltendl

}

CNode* CNode::GetNodeNext()

{

Return to m _ Next

}

# contains "CLinkList.h"

# contains "CNode.h"

Void text (); //Test function declaration

int main()

{

Cout & lt& lt "This is the function of encouragement"

text();

Returns 0;

}

Invalid text ()

{

Cout & lt& lt "This is a test function"

LinkList* pList = new linked list; //Create a memory linked list object

Cout & lt& lt"- Create list-"< & ltendl

pList->; create list(); //Initialize the function members of the linked list

pList->; ShowList();

cout & lt& ltendl

cout & lt& lt"-GetListNode-" & lt; & ltendl

LinkNode * pNode = NULL// Defines a temporary node class pointer to detect the members of the lookup function.

pNode = pList-& gt; GetListNode(3); //Test of finding the member function of the specified bit node by position.

Intermediate frequency (pNode)

{

Cout & lt& lt "The specified node was found by searching by location"

}

other

{

Cout & lt& lt Sorry, search by location did not find the specified bit node.

}

cout & lt& ltendl

Cout & lt& lt"- Insert list-"< & ltendl

pList->; insert list(0); //Test the member function of the inserted node.

pList->; ShowList();

cout & lt& ltendl

Cout & lt& lt"- Delete list-"< & ltendl

pList->; Delete list (0); //Delete the test of the member function of a node.

pList->; ShowList();

cout & lt& ltendl

cout & lt& lt"-GetHeadList-" & lt; & ltendl

pNode = NULL

pNode = pList-& gt; GetHeadList(); //Get the test of the member function of the head pointer

Intermediate frequency (pNode)

{

Cout & lt& lt "Head pointer returned"

}

other

{

Cout & lt& lt Sorry, the head pointer is empty.

}

cout & lt& ltendl

cout & lt& lt"-GetHeadList-" & lt; & ltendl

pList->; SetListData(3); //Test the member function that sets the node value in the linked list.

pList->; ShowList();

cout & lt& ltendl

cout & lt& lt"-getlist data-" & lt; & ltendl

cout & lt& lt" pList->; showlist data(3)= ";

pList->; showlist data(3); //Test the member function that gets the node value in the chain.

cout & lt& ltendl

cout & lt& lt"-destroy list(3)-" & lt; & ltendl

pList->; destroy list(3); //Test the member function of the linked list after destroying the third position.

pList->; ShowList();

cout & lt& ltendl

cout & lt& lt"-destroy list(0)-" & lt; & ltendl

pList->; DestroyList(0); //Test the member function of the linked list after destroying the zero position.

pList->; ShowList();

cout & lt& ltendl

Delete pList// Free up memory

PList = NULL// pointer is empty.

}

You ask too many questions. You didn't look carefully. I'll give you the homework I wrote for others. I've written it all. If there is any problem with the program, you can leave me a message.