Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
15
Добавлен:
17.04.2013
Размер:
3.54 Кб
Скачать
// lab2_zakon.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include <new.h>
#include "string.h"
typedef int ElemType;
struct Cell
{
	ElemType x;
    Cell* Next;
};
class CList
{
	  Cell Head;
   public:
   	  CList();
      ~CList();
	  void Add(ElemType x);
      void Insert(Cell* pos,ElemType x);
      void Delete(Cell* pos);
      Cell* First(void);
      Cell* End(void);
      Cell* Locate(ElemType x);
      ElemType Retrieve(Cell* pos);
      void MakeNull(void);
      Cell* Next(Cell* pos);
      Cell* Prev(Cell* pos);
	  void end_insert(ElemType x);
	  void Show();
};

CList::CList()
{
	Head.Next=NULL;
};
CList::~CList()
{
//	MakeNull();
};
void CList::Show()
{ Cell *temp_ptr = Head.Next;
  if (temp_ptr == NULL) cout<<"Empty Node"<<endl;
  else
  while (temp_ptr != NULL) 
  {
   cout<<temp_ptr->x<<" ";
   temp_ptr=temp_ptr->Next;
  }
  cout<<endl;

}
void CList::end_insert (ElemType x)
{  Cell *tail=&Head;  // ??®??                                     
   while(tail->Next!=NULL) 
   {tail=tail->Next;}
    tail->Next=new Cell;
 	tail->Next->x=x;
    tail->Next->Next=NULL;
	//tail->link=tail1;
}  
void CList::Add(ElemType x)
{
	Cell* p;
	p = Head.Next;
	Head.Next=new Cell;
	Head.Next->Next=p;
    Head.Next->x=x;
};
void CList::Insert(Cell* pos,ElemType x)
{
	Cell* temp;
	temp=pos->Next;
	pos->Next=new Cell;
	pos->Next->x=x;
	pos->Next->Next=temp;
};
void CList::Delete(Cell* pos)
{
	Cell* temp;
	temp=pos->Next;
	pos->Next=pos->Next->Next;
	delete temp;

};
Cell* CList::First(void)
{
	return Head.Next;
};
Cell* CList::End(void)
{ 	if(Head.Next!=NULL)
	{
		Cell* p=Head.Next;
		while(p->Next->Next!=NULL) p=p->Next;
		return p;
	};
	return NULL;

};
Cell* CList::Locate(ElemType x)
{
	if(Head.Next!=NULL)
	{
		Cell* p=&Head;
		while(p->Next!=NULL)
		{
			if(p->Next->x==x) return p->Next;
			p=p->Next;
		};
	};
	return NULL;
	
};
ElemType CList::Retrieve(Cell* pos)
{
	return pos->x;
};
void CList::MakeNull()
{
	while(End()!=NULL) Delete(End());
};
Cell* CList::Next(Cell* pos)
{
	return pos->Next;
};
Cell* CList::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;
};
int main(int argc, char* argv[])
{   
    CList badguys,goodguys;
	int s;
    char choise;
    cout<<"Prohodit golosovanie"<<endl;	
while(0==0)
{
loop1:
    cout<<"N - vvesti novogo zakonod; E - golosovanie zakonchilos`"<<endl;
	cin>>choise;
    if (choise=='E') break; 
	else if (choise!='N') goto loop1;
    cout<<"Vvedite identifikator zakonodatelya ";	
    cin>>s;
loop2:
    cout<<endl<<"Vvedite kak on golosoval(F/U/?) posmotret` status ";	
	cin>>choise;
    if (choise=='?') 
    {
		if     (badguys.Locate(s)!=NULL) cout<<"Ploho on progolosoval"<<endl;
		else if (goodguys.Locate(s)!=NULL) cout<<"Horoho on progolosoval"<<endl;
		else cout<<"Ne progolosoval"<<endl; 
		goto loop2;
	}
	if (choise=='U') 
	{ if (goodguys.Locate(s)!=NULL) goodguys.Delete(goodguys.Locate(s));
	  badguys.end_insert(s);
    }
    if (choise=='F') 
	{ if (badguys.Locate(s)!=NULL) goodguys.Delete(badguys.Locate(s));
      goodguys.end_insert(s);
	}
}
    cout<<"identifikatory loubiteley tyncov "<<endl;
    goodguys.Show();
    cout<<"identifikatory loubiteley jarenyh ili varenyh tyncov "<<endl;
    badguys.Show();



	return 0;
}

Соседние файлы в папке ООП_ЭТМО