数据结构学习总结-7-广义表-广义表的简单实现

时间:2024.3.31

/************************************************************************************ ** Program Name : Implementation of Generalized List

** Author : Lu Jian Hua

** Time : 20xx-5-29

************************************************************************************/

#include <iostream>

using namespace std ;

class GLNode // class of node in generalized lists

{

public:

GLNode() : type(0), next(NULL) {}

int type ; // type of the node

union

{

char value ; // value of the node

GLNode *link ;

} ;

GLNode *next ; // next node

} ;

GLNode* Create_GLNode()

{

GLNode *temp = NULL ; // notice: new a structor, but not only a null pointer

cout << "Another node ? (Y/N) " ;

char c = 0 ;

cin >> c ; cout << endl ;

if (c != 'n' && c != 'N')

{

temp = new GLNode() ; // new a GLNode object

cout << "Please select :" << endl << endl

<< "1> An atom" << endl << endl

<< "2> A GLNode link " ;

char select = 0 ;

cin >> select ; cout << endl ;

if (select == '1') // an atom

{

temp->type = 0 ; // indicate the node is an atom

cout << "Please enter the value : " ;

cin >> temp->value ;

cout << endl ;

}

else // a GLNode link

{

temp->type = 1 ;

temp->link = Create_GLNode() ;

}

temp->next = Create_GLNode() ; // continue the next node...

}

return temp ;

}

/************************************************************************************ ** Program Name : Deepth_Of_GLNode

** Parameters : GLNode *front (the front pointer)

** Value Returned : int (the deepth of the generalized list)

** Details : get the deepth of a generalized list

************************************************************************************/ int Deepth_Of_GLNode(const GLNode *front) // compute the deepth of the Generalized List {

static int max_deepth = 0 ;

int deepth = 0 ;

while (front)

{

if (front->type == 0) // if type=0, deepth = 0

deepth = 0 ;

else if (front->type == 1 && front->link == NULL)// if type=1 and the link is null, deepth=1

deepth = 1 ;

else

deepth += Deepth_Of_GLNode(front->link) ;// other conditions, the same disposal

if (max_deepth < deepth)

max_deepth = deepth ;

front = front->next ;

}

return (1+max_deepth) ;

}

/********************************************************************************* ** Program Name : GLNode_Printer

** Parameters : GLNode *front (the front pointer)

** Value Returned : void

** Details : print all the nodes of the generalized list

*********************************************************************************/ void GLNode_Printer(const GLNode *front)

{

const GLNode *recent = front ;

cout << "{" ;

while (recent)

{

if (recent->type == 0)

cout << recent->value ;

else if ( recent->type == 1 && recent->link == NULL)

cout << "{}" ;

else

GLNode_Printer(recent->link) ;

if (recent->next != NULL)

cout << "," ;

recent = recent->next ;

}

cout << "}" ;

}

int main()

{

GLNode *front = Create_GLNode() ;

GLNode_Printer(front) ;

cout << "\n\nThe max deepth of the Generalized list is : " << Deepth_Of_GLNode(front) << endl << endl ;

return 0 ;

}

/******************************************************************************** *

* Notice : This Program Can Be Launched In VC6.0 Environment

*

********************************************************************************/


第二篇:数据结构学习总结-4-队列-R


1:队列的性质

1> 先进的先出(FIFO)

2> 只能从front出,只能从rear进

2:队列的两个变量

1> front

2> rear

3> max_size

3:循环队列顺序表示时,空和满的表示

1> 空:if ( front == rear)

2> 满:if ( (rear+1)%max_size = front )

4:循环时用到的模思想

Rear = (rear+1)%max_size

5:队列的两个操作

1> 出队:front = (front+1)%max_size ;

2> 入队:rear = (rear+1)%max_size ;

6:注意

在循环队列中,当队列满时,仍会有一个空间没有使用

7:--------------------implementation of circle queue ( by array )-------------------------------------------

/********************************************************************************* ** Program Name : implementation of circle queue ( by array )

** Author Name : Lu Jian Hua

** Time : 20xx-5-23

**********************************************************************************/

#include <iostream>

using namespace std ;

class Queue // class of Queue

{

public:

Queue() ;

int GetValue() const ; // get the current value of Queue int Delete() ; // out_Queue

void Append(int value) ; // In__Queue

bool IsEmpty() const ; // is empty ?

bool IsFull() const ; // is full ?

private:

int front ; // front

int rear ; // rear

enum { MAX_SIZE = 10 } ; // Notice:remember ; at the end int element[MAX_SIZE] ; // implement with array

} ;

Queue::Queue() : front(0), rear(0) {}

int Queue::GetValue() const

{

if ( IsEmpty() )

{

cout << "The queue is empty!" << endl << endl ;

return 0 ;

}

int temp = front ;

return element[++temp] ;

}

void Queue::Append(int value)

{

if ( IsFull() )

{

cout << "The queue is full!" << endl << endl ;

}

rear = (rear+1) % MAX_SIZE ;

element[rear] = value ;

}

int Queue::Delete()

{

if ( IsEmpty() )

{

cout << "The queue is empty!" << endl << endl ;

return 0 ;

}

//return element[(++front) % MAX_SIZE] ; // different from the next sentence?? front = (front+1) % MAX_SIZE ;

return element[front] ;

}

bool Queue::IsEmpty() const

{

return (rear == front) ;

}

bool Queue::IsFull() const

{

return ( (rear+1) % MAX_SIZE == front ) ;

}

Queue* CreateQueue()

{

Queue *ptr = new Queue() ;

return ptr ;

}

int main()

{

Queue *ptr = CreateQueue() ;

while (true)

{

cout << "-------------------------------------------------" << endl

<< "1> Append" << endl

<< "2> Delete" << endl

<< "3> Get the value" << endl

<< "4> Is empty ? " << endl

<< "5> Is Full? " ;

char c = 0 ;

cin >> c ;

cout << endl ;

int value = 0 ;

switch (c)

{

case '1':

cout << "Enter the value : " ;

cin >> value ;

ptr->Append(value) ;

break ;

case '2':

cout << "The value deleted : " ;

if ( ptr->IsEmpty() )

cout << "NULL" << endl << endl ;

else

cout << ptr->Delete() << endl << endl ;

break ;

case '3':

cout << "The value getted : " ;

if ( ptr->IsEmpty() )

else

cout << ptr->GetValue() << endl << endl ;

break ;

case '4':

cout << "Is empty ? " << ( ptr->IsEmpty() ? "Yes" : "No" ) << endl << endl ; break ;

case '5':

cout << "Is full ? " << ( ptr->IsFull() ? "Yes" : "No" ) << endl << endl ; break ;

default:

break ;

}

}

return 0 ;

}

8:------------------------Implementation Of Queue By Chain--------------------------------

/********************************************************************************* ** Program Name : implementation of circle queue ( by chain )

** Author Name : Lu Jian Hua

** Time : 20xx-5-23

**********************************************************************************/

#include <iostream>

using namespace std ;

class Node

{

public:

Node() : data(0), next(NULL) {}

int data ;

Node *next ;

} ;

class Queue // class of Queue

{

public:

Queue() ;

Node* GetValue() const ; // get the current value of Queue void Delete() ; // out_Queue

void Append(int value) ; // In__Queue

void Cleaner() ; // cleaner of Queue bool IsEmpty() const ; // is empty ?

bool IsFull() const ; // is full ?

private:

Node* front ; // front

Node* rear ; // rear

} ;

Queue::Queue() : front(NULL), rear(NULL) {}

Node* Queue::GetValue() const

{

if ( IsEmpty() )

{

cout << "The queue is empty!" << endl << endl ;

return 0 ;

}

return front ;

}

void Queue::Append(int value)

{

Node *temp = new Node() ;

temp->data = value ;

if (front == NULL) // no element in the queue {

front = temp ;

rear = front ;

rear->next = NULL ;

}

else

{

rear->next = temp ;

rear = temp ;

rear->next = NULL ;

}

}

void Queue::Delete()

{

if ( IsEmpty() )

{

cout << "The queue is empty!" << endl << endl ;

return ;

}

Node *record = front ;

front = front->next ;

delete record ;

cout << "The specific node has beend deleted!" << endl << endl ;

}

void Queue::Cleaner()

{

while (front)

{

Node *record = front->next ;

delete front ;

front = record ;

}

cout << "Cleaner has done it's work...\n\n" ;

}

bool Queue::IsEmpty() const

{

return (front == NULL) ;

}

bool Queue::IsFull() const

{

return ( false ) ; // never full until no enough memory accommodated }

Queue* CreateQueue()

{

Queue *ptr = new Queue() ;

return ptr ;

}

int main()

{

Queue *ptr = CreateQueue() ;

while (true)

{

cout << "-------------------------------------------------" << endl

<< "1> Append" << endl

<< "2> Delete" << endl

<< "3> Get the value" << endl

<< "4> Is empty ? " << endl

<< "5> Is Full? " << endl

<< "6> Release the queue? " ;

char c = 0 ;

cin >> c ;

cout << endl ;

int value = 0 ;

} } return 0 ; switch (c) { case '1': cout << "Enter the value : " ; cin >> value ; ptr->Append(value) ; break ; case '2': ptr->Delete() ; break ; case '3': cout << "The value getted : " ; if ( ptr->IsEmpty() ) cout << "NULL" << endl << endl ; else cout << (ptr->GetValue())->data << endl << endl ; break ; case '4': cout << "Is empty ? " << ( ptr->IsEmpty() ? "Yes" : "No" ) << endl << endl ; break ; case '5': cout << "Is full ? " << ( ptr->IsFull() ? "Yes" : "No" ) << endl << endl ; break ; case '6': ptr->Cleaner() ; break ; default: break ; }

更多相关推荐:
数据结构实训总结

这次课程设计的心得体会通过实习我的收获如下1、巩固和加深了对数据结构的理解,提高综合运用本课程所学知识的能力。2、培养了我选用参考书,查阅手册及文献资料的能力。培养独立思考,深入研究,分析问题、解决问题的能力。…

数据结构实习报告_图

数据结构课程设计实习报告题目学号姓名年级学院专业完成日期授课教师图的基本操作1210522何厚华大二计算机与控制工程学院计算机科学与技术20xx年5月21日辛运帏目录1题目22要求23程序实现331程序运行及编...

数据结构实训报告

实训报告实训题目校园导游程序学院计算机科学与技术学院专业软件工程班级20xx级学号120xx60220学生姓名熊齐超指导教师张丽20xx年7月10日一实训目的及要求数据结构是计算机课程的一门重要的基础课它的教学...

数据结构实验报告及心得体会

20XX~20XX第一学期数据结构实验报告班级:信管一班学号:*********姓名:***实验报告题目及要求一、实验题目设某班级有M(6)名学生,本学期共开设N(3)门课程,要求实现并修改如下程序(算法)。1…

数据结构 实习报告

长春理工大学实习类别学院专业班级姓名学生实习报告20xx20xx学年第一学期课程设计计算机学院网络工程20xx年12月29日123一需求分析参加运动会有n个学校学校编号为1n比赛分成m个男子项目和w个女子项目项...

数据结构实习总结

数据结构课程实习总结(或XX基础综合实训实习总结或XX毕业实习总结)(学院根据实习安排及执行情况,概述实习的经验与不足)本次实训首先巩固课本上重要知识点,首先是一些基本操作,掌握线性表在单链存储结构中实现基本运…

数据结构实习报告

数据结构上机报告学号20xx10020xx班级序号11613112姓名陶剑浩指导老师吴亮成绩中国地质大学武汉信息工程学院信息工程系20xx年12月实习一线性表及其应用问题描述大数运算计算n的阶乘ngt20基本要...

数据结构实验报告格式

实验报告格式一实验目的二实验内容实验内容包括1程序要求2根据程序要求写出程序源程序两部分内容三程序调试过程记录四实验结果实验结果包括1写出试验结果实验目的可参考习题书2实验总结两部分内容

《数据结构》实验指导书

指导书软件学院20xx年9月数据结构实验概述实习目的和要求数据结构在计算机科学中是一门实践性较强的专业基础课上机实习是对学生的一种全面综合训练是与课堂听讲自习和练习相辅相成的必不可少的一个教学环节实习着眼于原理...

算法数据结构总结

大学算法与数据结构课程设计课程专业班级学号姓名20xx年11月18日本次算法与数据结构实践课中我们小组主要选择了两个课题一个是迷宫的创建及求解问题另一个是停车场管理系统问题还选做了一个敢死队的问题在迷宫创建及求...

数据结构停车场管理系统课设报告模板及实现代码

数据结构课程设计上机实习报告课设题目系部班级学生姓名学号序号指导教师时间停车场管理系统停车场管理系统一设计目的1进一步熟悉VC开发环境熟悉用C语言完成一个应用程序的设计过程掌握有关编辑调试和整合程序的方法和技巧...

c语言中进制转换数据结构实训报告

进制之间转换专班姓学第0页共15页数据结构程序设计报告业计算机网络技术级名号二一二年四月三十日目录1需求分析12概要设计23采用的算法流程图24详细设计25调试分析36用户使用说明37测试结果38附录131需求...

数据结构实习总结(49篇)