Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / С++.ЭТМО / 1 - Lexemy / strList
.h#include <iostream.h>
#include <new.h>
#include <string.h>
struct Cell
{
char* x;
Cell* Next;
};
class StList
{
Cell Head;
public:
StList();
~StList();
void Add(char* x);
void Insert(Cell* pos,char* x);
void Delete(Cell* pos);
void DeleteCur(Cell* pos);
Cell* First(void);
Cell* End(void);
Cell* Locate(char* x);
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* x)
{
Cell* p;
p=Head.Next;
Head.Next=new Cell;
Head.Next->Next=p;
Head.Next->x = new char[strlen(x)+1];
strcpy(Head.Next->x,x);
};
void StList::Insert(Cell* pos,char* x)
{
Cell* temp;
temp=pos->Next;
pos->Next=new Cell;
pos->Next->x=new char[strlen(x)+1];
strcpy(pos->Next->x,x);
pos->Next->Next=temp;
};
void StList::Delete(Cell* pos)
{
Cell* temp;
temp=pos->Next;
delete[] temp->x;
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* x)
{
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* x)
{
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->x<<endl;
cout.flush();
};
cout<<endl;
cout.flush();
};
Соседние файлы в папке 1 - Lexemy