Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
13
Добавлен:
17.04.2013
Размер:
2.93 Кб
Скачать
#include <iostream.h>
#include <new.h>
#include <string.h>

struct Cell
{
	char* f;
	char* i;
	char* o;
	int d;
	Cell* Next;
};

class StList
{
	Cell Head;
public:
	StList();
	~StList();
	void Add(char* f,char* i,char* o,int d);
	void Insert(Cell* pos,char* f,char* i,char* o,int d);
	void Delete(Cell* pos);
	void DeleteCur(Cell* pos);
	Cell* First(void);
	Cell* End(void);
//	Cell* Locate(char* f,char* i,char* o,int d);
//	Cell* PrevLocate(char* x);
//	char* Retrieve(Cell* pos);
	void MakeNull(void);
	Cell* Next(Cell* pos);
	Cell* Prev(Cell* pos);
	void PrnStList(void);
};

StList::StList()
{
	Head.Next=NULL;
};

StList::~StList()
{
	MakeNull();
};

void StList::Add(char* f,char* i,char* o,int d)
{
	Cell* p;
	p=Head.Next;
	Head.Next=new Cell;
	Head.Next->Next=p;
	Head.Next->f = new char[strlen(f)+1];
	strcpy(Head.Next->f,f);
	Head.Next->i = new char[strlen(i)+1];
	strcpy(Head.Next->i,i);
	Head.Next->o = new char[strlen(o)+1];
	strcpy(Head.Next->o,o);
	Head.Next->d=d;
};

void StList::Insert(Cell* pos,char* f,char* i,char* o,int d)
{
	Cell* temp;
	temp=pos->Next;
	pos->Next=new Cell;
	pos->Next->f=new char[strlen(f)+1];
	strcpy(pos->Next->f,f);
	pos->Next->i=new char[strlen(i)+1];
	strcpy(pos->Next->i,i);
	pos->Next->o=new char[strlen(o)+1];
	strcpy(pos->Next->o,o);
	pos->Next->d=d;
	pos->Next->Next=temp;
};

void StList::Delete(Cell* pos)
{
		Cell* temp;
		
		temp=pos->Next;

		delete[] temp->f;
		delete[] temp->i;
		delete[] temp->o;

		pos->Next=pos->Next->Next;
		delete temp;
};

void StList::DeleteCur(Cell* pos)
{
	Cell* tmp;
	tmp=&Head;
	while(tmp->Next!=NULL)
	{
		if(tmp->Next=pos) Delete(tmp);
	};
};

Cell* StList::First(void)
{
	return Head.Next;
};
Cell* StList::End(void)
{
		Cell* p=&Head;
		if(p->Next==NULL) return NULL;
		while(p->Next->Next!=NULL) p=p->Next;
		return p;
};
/*Cell* StList::Locate(char* f,char* i,char* o,int d)
{
	if(Head.Next!=NULL)
	{
		Cell* p=&Head;
		while(p->Next!=NULL)
		{
			if(!strcmp(p->Next->x,x)) return p->Next;
			p=p->Next;
		};
	};
	return NULL;
};*/

/*Cell* StList::PrevLocate(char* f,char* i,char* o,int d)
{
	if(Head.Next!=NULL)
	{
		Cell* p=&Head;
		while(p->Next!=NULL)
		{
			if(!strcmp(p->Next->x,x)) return p;
			p=p->Next;
		};
	};
	return NULL;
};*/

/*char* StList::Retrieve(Cell* pos)
{
	return pos->x;
};*/

void StList::MakeNull()
{
	while(End()!=NULL) Delete(End());
};

Cell* StList::Next(Cell* pos)
{
	return pos->Next;
};

Cell* StList::Prev(Cell* pos)
{
	Cell* p=&Head;
	while(p->Next!=pos && p->Next!=NULL) p=p->Next;
	if(p->Next==pos) return p;
	else return NULL;
};

void StList::PrnStList(void)
{

		Cell* p=&Head;
		while(p->Next!=NULL)
		{
			p=p->Next;
			cout<<p->f<<" "<<p->i<<" "<<p->o<<" "<<p->d;
			cout.flush();
		};
		cout<<endl;
		cout.flush();
};
Соседние файлы в папке 3 - Karman sort