为了账号安全,请及时绑定邮箱和手机立即绑定

有大佬可以发下这课的源码吗?

可以运行的源码即可,我编写的莫名其妙有错误,请大佬们发下源码

正在回答

1 回答

MyList.h

#include"stdafx.h"

#ifndef LIST_H

#define LIST_H

#include"Coordinate.h"


class List

{

public:

List(int size);

~List();

void ClearList();

bool ListEmpty();

int ListLength();

bool GetElem(int i, Coordinate *e);

int LocateElem(Coordinate  *e);

bool PriorElem(Coordinate*currentElem, Coordinate*preElem);

bool NextElem(Coordinate *currentElem, Coordinate *nextElem);

bool ListInsert(int i, Coordinate *e);

bool ListDelete(int i, Coordinate*e);

void ListTraverse();

//C语言描述  顺序表

/*bool InitList(List **list);

void DestoryList(List *list);

void ClearList(List *list);

bool ListEmpty(List *list);

int ListLength(List *list);

bool GetElem(List *list, init i, Elem *e);

int LocateElem(List*list, Elem *e);

bool PriorElem(List *list, Elem*currentElem, Elem*preElem);

bool NextElem(List *list, Elem *currentElem, Elem*nextElem);

bool ListInsert(List *list, int i, Elem *e);

bool ListDelete(List *list, int i, Elem *e);

void ListTraverse(List *list);*/

private:

Coordinate *m_pList;

int m_iSize;

int m_iLength;


};


#endif


Coordinate.cpp

#include"stdafx.h"

#include"Coordinate.h"

using namespace std;


Coordinate::Coordinate(int x, int y)

{

m_iX = x;

m_iY = y;

}

void Coordinate::printCoordinate()

{

cout << "(" << m_iX << "," << m_iY << ")" << endl;

}

ostream &operator<<(ostream &out, Coordinate &coor)

{

out << "(" << coor.m_iX << "," << coor.m_iY << ")" << endl;

return out;

}

bool Coordinate::operator==(Coordinate &coor)

{

if (this->m_iX == coor.m_iX&&this->m_iY == coor.m_iY)

{

return true;

}

return false;

}

Coordinate.h

#include"stdafx.h"

#include"iostream"

#include"ostream"


using namespace std;

#ifndef COORDINATE_H

#define COORDINATE_H


class Coordinate

{

friend ostream &operator<<(ostream &out, Coordinate &coor);

public:

Coordinate(int x = 0, int y = 0);

void printCoordinate();

bool operator==(Coordinate &coor);

private:

int m_iX;

int m_iY;

};


#endif

MyList.cpp

#include"stdafx.h"

#include"MyList.h"

#include"iostream"


using namespace std;



List::List(int size)

{

m_iSize = size;

m_pList = new Coordinate[m_iSize];

m_iLength = 0;

}

List::~List()

{

delete[]m_pList;

m_pList = 0;

}

void List::ClearList()

{

m_iLength = 0;

}

bool List::ListEmpty()

{

if (m_iLength == 0)

{

return true;

}

return false;

}

int List::ListLength()

{

return m_iLength;

}

bool List::GetElem( int i, Coordinate*e)

{

if (i < 0 || i >= m_iSize)

{

return false;

}

*e = m_pList[i];

return true;

}

int List::LocateElem(Coordinate *e)

{

for (int i = 0; i < m_iLength; i++)

{

if (m_pList[i] == *e)

{

return i;

}


}

return -1;

}

bool List::PriorElem(Coordinate*currentElem, Coordinate*preElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == 0)

{

return false;

}

else

{

*preElem = m_pList[temp - 1];

return true;

}

}

}

bool List::NextElem(Coordinate *currentElem, Coordinate *nextElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == m_iLength-1)

{

return false;

}

else

{

*nextElem = m_pList[temp+1];

return true;

}

}


}

bool List::ListInsert(int i, Coordinate *e)

{

//int temp;


if (i<0 || i>m_iLength)

{

return false;

}

for (int k =m_iLength-1; k>=i; k--)

{

m_pList[k + 1] = m_pList[k];

}

m_pList[i] = *e;

m_iLength++;

return true;

}

bool List::ListDelete(int i, Coordinate*e)

{

if (i<0 || i >m_iLength)

{

return false;

}

*e = m_pList[i];

for (int k = i+1; k < m_iLength - 1; k++)

{

m_pList[k - 1] = m_pList[k];

}

m_iLength--;

return true;

}

void List::ListTraverse()

{

for (int i = 0; i < m_iLength; i++)

{

cout << m_pList[i] << endl;

//m_pList[i].printCoordinat();

}

}

// listtest.cpp : 定义控制台应用程序的入口点。

//


#include "stdafx.h"

#include"iostream"

#include"MyList.h"

using namespace std;


int _tmain(int argc, _TCHAR* argv[])

{

Coordinate e1(3,5);

Coordinate e2(5,7);

Coordinate e3(6,8);

/*Coordinate e4 = 2;

Coordinate e5 = 9;

Coordinatee6 = 1;

Coordinate e7 = 8;*/

Coordinate temp(0,0);

List *p = new List(10);

//cout << "length:" << p->ListLength() << endl;

//p->ListInsert(0, &e1);

//cout << "length:" << p->ListLength() << endl;

p->ListInsert(0, &e1);

p->ListInsert(1, &e2);

p->ListInsert(2, &e3);

/*p->ListInsert(3, &e4);

p->ListInsert(4, &e5);

p->ListInsert(5, &e6);#include"stdafx.h"

#include"MyList.h"

#include"iostream"


using namespace std;



List::List(int size)

{

m_iSize = size;

m_pList = new Coordinate[m_iSize];

m_iLength = 0;

}

List::~List()

{

delete[]m_pList;

m_pList = 0;

}

void List::ClearList()

{

m_iLength = 0;

}

bool List::ListEmpty()

{

if (m_iLength == 0)

{

return true;

}

return false;

}

int List::ListLength()

{

return m_iLength;

}

bool List::GetElem( int i, Coordinate*e)

{

if (i < 0 || i >= m_iSize)

{

return false;

}

*e = m_pList[i];

return true;

}

int List::LocateElem(Coordinate *e)

{

for (int i = 0; i < m_iLength; i++)

{

if (m_pList[i] == *e)

{

return i;

}


}

return -1;

}

bool List::PriorElem(Coordinate*currentElem, Coordinate*preElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == 0)

{

return false;

}

else

{

*preElem = m_pList[temp - 1];

return true;

}

}

}

bool List::NextElem(Coordinate *currentElem, Coordinate *nextElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == m_iLength-1)

{

return false;

}

else

{

*nextElem = m_pList[temp+1];

return true;

}

}


}

bool List::ListInsert(int i, Coordinate *e)

{

//int temp;


if (i<0 || i>m_iLength)

{

return false;

}

for (int k =m_iLength-1; k>=i; k--)

{

m_pList[k + 1] = m_pList[k];

}

m_pList[i] = *e;

m_iLength++;

return true;

}

bool List::ListDelete(int i, Coordinate*e)

{

if (i<0 || i >m_iLength)

{

return false;

}

*e = m_pList[i];

for (int k = i+1; k < m_iLength - 1; k++)

{

m_pList[k - 1] = m_pList[k];

}

m_iLength--;

return true;

}

void List::ListTraverse()

{

for (int i = 0; i < m_iLength; i++)

{

cout << m_pList[i] << endl;

//m_pList[i].printCoordinat();

}

}

main.cpp

// listtest.cpp : 定义控制台应用程序的入口点。

//


#include "stdafx.h"

#include"iostream"

#include"MyList.h"

using namespace std;


int _tmain(int argc, _TCHAR* argv[])

{

Coordinate e1(3,5);

Coordinate e2(5,7);

Coordinate e3(6,8);

/*Coordinate e4 = 2;

Coordinate e5 = 9;

Coordinatee6 = 1;

Coordinate e7 = 8;*/

Coordinate temp(0,0);

List *p = new List(10);

//cout << "length:" << p->ListLength() << endl;

//p->ListInsert(0, &e1);

//cout << "length:" << p->ListLength() << endl;

p->ListInsert(0, &e1);

p->ListInsert(1, &e2);

p->ListInsert(2, &e3);

/*p->ListInsert(3, &e4);

p->ListInsert(4, &e5);

p->ListInsert(5, &e6);#include"stdafx.h"

#include"MyList.h"

#include"iostream"


using namespace std;



List::List(int size)

{

m_iSize = size;

m_pList = new Coordinate[m_iSize];

m_iLength = 0;

}

List::~List()

{

delete[]m_pList;

m_pList = 0;

}

void List::ClearList()

{

m_iLength = 0;

}

bool List::ListEmpty()

{

if (m_iLength == 0)

{

return true;

}

return false;

}

int List::ListLength()

{

return m_iLength;

}

bool List::GetElem( int i, Coordinate*e)

{

if (i < 0 || i >= m_iSize)

{

return false;

}

*e = m_pList[i];

return true;

}

int List::LocateElem(Coordinate *e)

{

for (int i = 0; i < m_iLength; i++)

{

if (m_pList[i] == *e)

{

return i;

}


}

return -1;

}

bool List::PriorElem(Coordinate*currentElem, Coordinate*preElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == 0)

{

return false;

}

else

{

*preElem = m_pList[temp - 1];

return true;

}

}

}

bool List::NextElem(Coordinate *currentElem, Coordinate *nextElem)

{

int temp = LocateElem(currentElem);

if (temp == -1)

{

return false;

}

else

{

if (temp == m_iLength-1)

{

return false;

}

else

{

*nextElem = m_pList[temp+1];

return true;

}

}


}

bool List::ListInsert(int i, Coordinate *e)

{

//int temp;


if (i<0 || i>m_iLength)

{

return false;

}

for (int k =m_iLength-1; k>=i; k--)

{

m_pList[k + 1] = m_pList[k];

}

m_pList[i] = *e;

m_iLength++;

return true;

}

bool List::ListDelete(int i, Coordinate*e)

{

if (i<0 || i >m_iLength)

{

return false;

}

*e = m_pList[i];

for (int k = i+1; k < m_iLength - 1; k++)

{

m_pList[k - 1] = m_pList[k];

}

m_iLength--;

return true;

}

void List::ListTraverse()

{

for (int i = 0; i < m_iLength; i++)

{

cout << m_pList[i] << endl;

//m_pList[i].printCoordinat();

}

}

p->ListInsert(6, &e7);*/

p->ListTraverse();


//p->PriorElem(&e4, &temp);

//cout << "temp:" << temp << endl;

//p->NextElem(&e4, &temp);

//cout << "temp:" << temp << endl;

/*p->GetElem(0, &temp);

cout << "#" << temp << endl;

cout << p->LocateElem(&temp);*/


/*p->ListDelete(0, &temp);

if (!p->ListEmpty())

{

cout << "not empty" << endl;

}

p->ClearList();


p->ListTraverse();

if (p->ListEmpty())

{

cout << "empty" << endl;

}

cout << "#" << temp << endl;*/

delete p;

system("pause");

return 0;

}


1 回复 有任何疑惑可以回复我~
#1

C10H16N5O13P3 提问者

非常感谢!
2017-08-17 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
数据结构探险之线性表篇
  • 参与学习       57472    人
  • 解答问题       257    个

线性表的主体顺序表和链表,让学员能够将知识融会贯通学以致用

进入课程

有大佬可以发下这课的源码吗?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信