|
Составление программы
???????????? ?????? ? ????????????????? ??????????? ???
??????? ?????????.
?????????? ??????????????? ??????????-???????????????
???????????
?. ?.?. ???????????
??????? ?????????????? ??????????
????? ??? ???????????????.
?????? ?????
????: ??????.?.
???? 3??-2-26
????/h1>
1998
?????????.
??????????? ?????????????
?? ??:
?????? ???? ?????
??????????? ? ????????????
??? ? ???? ???? ???? ???:
1. ???????? ???;
2. ???????????????;
3. ??? ??? ? ????
4. ????????? ??? ???;
5. ???? ??? ? ???
6. ???????? ? ??? ?????;
7. ??? ?????????;
8. ?????????;
9. ?????????????.
??????? ?????
??????????? ?????? ???????
????????? ??? ????? ?? ????
?? ??? ???
?? ???? ???? ????? ? ??????
????? ???????? ?? ??? ? ????
????????? ?? ????? ???.
??????????? ?? ????? ??? ??
???????? PC ??????????????
????Borland3.01 ???. ?? ???????
??????? ???????????? ?????
????????? ????????? ?????
?????? ?????????? ? ????? ?
?? ??????????? ???.
??? ?????/I>.
#include
class List
?{struct Tree
?? {int Body;
??? Tree *LP;
??? Tree *RP;
??? Tree(int Bdy=0) {Body=Bdy; LP=NULL;
RP=NULL;}
??? ~Tree() {Body=0; LP=NULL;
RP=NULL;}
?? };
? public:
?? List(int Digit=0);
?? Tree *Root;
? ?List *LNext;
?? List *LPrev;
?};
List::List(int Digit)
?{Root=NULL;
? for (int i=Digit*10; i RP=NULL;
??? if (Root==NULL)
???? Root=PTree;
??? else
???? {Tree *PTree1=Root;
????? do
?????? {if (PTree1->LP!=NULL)
??????????? ?PTree1=PTree1->LP;}
????? while (PTree1->LP!=NULL);
????? PTree1->LP=PTree;
????? PTree=NULL; PTree1=NULL;
???? }
?? }
?}
class TreeWork : private List
?{public:
?? void TreeWorkStart();
? private:
?? int ElementQuantity;
?? int Mass;
?? int i;
?? List *BegP;
?? List *PList;
?? int MainMenu();
?? int Work(int Task);
?? int MakeNewList();
?? int AddElements();
?? int PrintList();
?? void EraseList();
?? int DeleteElement();
?? int FindElement();
?? int SubMenu();
?? int SubWork(int Task);
?? int SortByIncrease();
?? int SortByDecrease();
?? int SaveList();
?? int OpenList();
? protected:
?? void GoThroughTree(Tree *L);
?? void Erase(Tree *L);
?};
int TreeWork::MainMenu()
?{cout<br>
? cout<<" 1. Make New List." <br>
? cout<<" 2. Add Element."?? <br>
? cout<<" 3. Print List."??? <br>
? cout<<" 4. Delete Element."<br>
? cout<<" 5. Save List."???? <br>
? cout<<" 6. Erase List."??? <br>
? cout<<" 7. Open File."???? <br>
? cout<<" 8. Find Element."? <br>
? cout<<" 9. Sort List."???? i;
??? if (i 9);
? return i;
?}
int TreeWork::SubMenu()
?{cout<br>
? cout<<"1. Sort list by increase." i;
??? if (i 2);
? return i;
?}
int TreeWork::SubWork(int Task)
?{switch (Task)
?? {case 1 : SortByIncrease(); break;
//Increase
??? case 2 : SortByDecrease(); break;
//Decrease
?? }
? return 0;
?}
int TreeWork::Work(int Task)
?{switch (Task)
?? {case 1 :
ElementQuantity=MakeNewList();? break;
//Make New List
??? case 2 :
ElementQuantity+=AddElements(); break;
//Add Element
??? case 3 :
PrintList();??????????????????
? break; //Print List
??? case 4 :
DeleteElement();???????????????
break; //Delete Element
??? case 5 :
SaveList();???????????????????
? break; //Save List
??? case 6 : ElementQuantity=0; EraseList();
break; //Erase List
??? case 7 :
OpenList();??????????????????
?? break; //Open File
??? case 8 :
FindElement();????????????????
? break; //Find Element
??? case 9 :
SubWork(SubMenu());????????????
break; //Sort List
??? case 0 :
EraseList();??????????????????
? return -1; //Exit
?? }
? return 0;
?}
void TreeWork::TreeWorkStart()
?{ElementQuantity=0;
? do {} while (Work(MainMenu())!=-1);
?}
int TreeWork::MakeNewList()
?{if (BegP!=NULL)
?? {cout<
??? if (Quant<1)
???? cout<
?? }
? while (Quant Digit;
??? PList=new List(Digit);
??? if (BegP==NULL)
???? {BegP=PList;
????? BegP->LNext=BegP;
????? BegP->LPrev=BegP;
????? PList=NULL;}
??? else
???? {List *PList1=BegP->LPrev;
????? if (PList1==BegP)
?????? {BegP->LNext=PList;
??????????? BegP->LPrev=PList;
??????????? PList->LNext=BegP;
??????????? PList->LPrev=BegP;
??????????? PList=NULL;
PList1=NULL;}
????? else
?????? {BegP->LPrev=PList;
??????????? PList1->LNext=PList;
??????????? PList->LNext=BegP;
??????????? PList->LPrev=PList1;
??????????? PList=NULL;
PList1=NULL;}
???? }
?? }
? return Quant;
?}
int TreeWork::AddElements()
?{if (BegP==NULL)
?? {MakeNewList(); return 0;}
? int Quant;
? cout Quant;
??? if (Quant<1)
???? cout<
?? }
? while (Quant Digit;
??? PList=new List(Digit);
??? List *PList1=BegP->LPrev;
??? if (PList1==BegP)
???? {BegP->LNext=PList;
????? BegP->LPrev=PList;
????? PList->LPrev=BegP;
????? PList->LNext=BegP;
????? PList1=NULL; PList=NULL;}
??? else
???? {BegP->LPrev=PList;
????? PList->LNext=BegP;
????? PList->LPrev=PList1;
????? PList1->LNext=PList;
????? PList=NULL; PList1=NULL;}
?? }
? return Quant;
?}
int TreeWork::PrintList()
?{if (BegP==NULL)
?? {cout<br>
return -1;}
? cout<
"<
??? cout LNext;}
? while (PList!=BegP);
? return 0;
?}
void TreeWork::GoThroughTree(Tree *L)
?{Tree *PL=L, *PL1;
? if (PL->LP!=NULL)
?? {PL1=PL;
??? PL=PL->LP;
??? cout RP;
??? cout Body LP;
??? Erase(PL);}
? if (PL->RP!=NULL)
?? {PL=PL->RP;
??? Erase(PL);}
? PL->LP=NULL;
? PL->RP=NULL;
?}
void TreeWork::EraseList()
?{if (BegP!=NULL)
?? {do
???? {List *PList1=BegP->LNext;
????? PList=PList1->LNext;
????? BegP->LNext=PList;
????? PList->LPrev=BegP;
????? Erase(PList1->Root);
????? delete [] PList1;
???? }
??? while (PList!=BegP);
??? BegP=NULL; PList=NULL;
?? }
?}
int TreeWork::DeleteElement()
?{cout ElementQuantity Number LNext;
? List *PList1=PList->LNext, *PList2=PList-
>LPrev;
? if (PList==BegP)
?? {PList1->LPrev=PList2;
??? PList2->LNext=PList1;
??? PList->LNext=NULL;
??? PList->LPrev=NULL;
??? delete [] PList;
??? BegP=PList1;
??? PList1=NULL; PList2=NULL;}
? else
?? {PList1->LPrev=PList2;
??? PList2->LNext=PList1;
??? PList->LNext=NULL;
??? PList->LPrev=NULL;
??? delete [] PList;
??? PList1=NULL; PList2=NULL;}
? ElementQuantity--;
? return 0;
?}
int TreeWork::FindElement()
?{cout Root;
??? if (Number>PT->Body && Number Root);
????? PList=NULL; cout LNext;
?? }
? while (PList!=BegP);
? cout<
list!"<br>
? PList=NULL;
? return -1;
?}
int TreeWork::SortByIncrease()
?{
? if(BegP==NULL)
{cout Root-
>Body)
?????? {Tree *PT;
??????????? PT=PList1->Root;
??????????? PList1->Root=PList-
>Root;
??????????? PList->Root=PT;
??????????? PT=NULL;}
????? PList1=PList1->LNext;
???? }
??? while (PList1!=BegP);
??? PList=PList->LNext;
?? }
? while (PList!=BegP);
? return 0;
?}
int TreeWork::SortByDecrease()
?{
? if(BegP==NULL)
{cout Root-
>Body)
?????? {Tree *PT;
??????????? PT=PList1->Root;
??????????? PList1->Root=PList-
>Root;
??????????? PList->Root=PT;
??????????? PT=NULL;}
????? PList1=PList1->LNext;
???? }
??? while (PList1!=BegP);
??? PList=PList->LNext;
?? }
? while (PList!=BegP);
? return 0;
?}
int TreeWork::SaveList()
?{if (BegP==NULL)
?? {cout<
? F.open(FileName);
? PList=BegP;
? do
?? {i=0;
??? Mass=PList->Root->Body;
??? PList=PList->LNext;
??? if (PList!=BegP)
???? F<br>
??? else
???? F<br>
?? }
? while (PList!=BegP);
? F.close();
? delete [] FileName;
? return 0;
?}
int TreeWork::OpenList()
?{if (BegP!=NULL)
?? {cout<
exist!" FileName;
? ifstream f;
? ElementQuantity=0;
? f.open(FileName);
? char Next;
? Next=f.peek();
? while (Next!=EOF)
?? {
??? f>>Mass;
??? PList=new List(Mass/10);
??? if (BegP==NULL)
???? {BegP=PList;
????? BegP->LNext=BegP;
????? BegP->LPrev=BegP;
????? PList=NULL;}
??? else
?? ??{List *PList1=BegP->LPrev;
????? if (PList1==BegP)
?????? {BegP->LNext=PList;
??????????? BegP->LPrev=PList;
??????????? PList->LNext=BegP;
??????????? PList->LPrev=BegP;
??????????? PList=NULL;
PList1=NULL;}
????? else
?????? {BegP->LPrev=PList;
??????????? PList1->LNext=PList;
??????????? PList->LNext=BegP;
??????????? PList->LPrev=PList1;
??????????? PList=NULL;
PList1=NULL;}
???? }
??? Next=f.peek();
??? ElementQuantity++;
?? }
? f.close();
? delete [] FileName;
? return 0;
?}
TreeWork TW;
void main()
?{TW.TreeWorkStart();}
????????? ?????
???????:
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5.
Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your
choice :
?? ???? ??? ???? ???1:
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?
5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit.
Your choice : 1 Input kol-vo of elements:
????????? ????? ???? (????
??4):
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?
5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit.
Your choice : 1 Input kol-vo of elements: 4 Input digit:
?????????? ??????:
Input kol-vo of elements: 4 Input digit: 1 Input digit: 2 Input digit: 3 Input digit: 4
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete
Element. ?5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort
List. ?0. Exit. Your choice :
??? ?????? ???? ??????? ???
???? ???????? ?????:
Input digit: 1 Input digit: 2 Input digit: 3 Input digit: 4 Main Menu: ?1. Make New List. ?2.
Add Element. ?3. Print List. ?4. Delete Element. ?5. Save List. ?6. Erase List. ?7. Open
File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 2 Input kol-vo of elements:
????? ??? ??? ????? ????? ?
???? ??????????? ???. ????
1?? (?? ????:
Input digit: 2 Input digit: 3 Input digit: 4 Main Menu: ?1. Make New List. ?2. Add
Element. ?3. Print List. ?4. Delete Element. ?5. Save List. ?6. Erase List. ?7. Open File. ?
8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 2 Input kol-vo of elements: 1 Input
digit:
??? ????? ?? ??? ???? ??????.
??? ???? ????? ????? ??????
??? ? ??????? ???????, ?????
??????? ??? ? ??? ????:
?1 element: 1234 ?2 element: 2345 ?3 element: 3456 ?4 element: 4567 ?5 element: 2345
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5.
Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your
choice :
?????????? ?? ??? ?? ????? ?
?? ? ???????????????, ?????
??????????????
?2 element: 2345 ?3 element: 3456 ?4 element: 4567 ?5 element: 2345 Main Menu: ?1. Make
New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5. Save List. ?6. Erase List. ?
7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 4 Input number of
element: 5
??? ?? ???? ?????? ???????. ?
?? ???? ????? ???? ????????
?????? ???????, ??????????
????? ???:
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5. Save
List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 5
Input file name: demon13.txt
??? ???????????? ? ??? ???
??? ??. ? ? ??????????, ?????
? ???? ???:
5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your
choice : 5 Input file name: demon13.txt Main Menu: ?1. Make New List. ?2. Add Element. ?3.
Print List. ?4. Delete Element. ?5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9.
Sort List. ?0. Exit. Your choice : 6
??? ?? ????? ???? ?????? ?
????????? ????? ???, ?????
?????????:
5. Save List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice :
6 Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5. Save
List. ?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 7 Input
file name: demon13.txt
??? ?? ????? ??????? ?? ?? - ?
????????????????? ???????
???????:
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5. Save List.
?6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice :8 Input number,
you want to find: 2 The first element that we fined out: 1234
??????? ????? ????????? ?
?????????. ???? ??/??????
Main Menu: ?1. Make New List. ?2. Add Element. ?3. Print List. ?4. Delete Element. ?5. Save List. ?
6. Erase List. ?7. Open File. ?8. Find Element. ?9. Sort List. ?0. Exit. Your choice : 9 Sub Menu: 1.
Sort list by increase. 2. Sort list by decrease. Your choice:
??? ?????????? ?????? ????
?? (?? ????? ??? ??? ?????). ?
?? ????? ???? ??/???! ?? ??
????????????? ? ??????? ???
???? ???, ? ???????????????
????????????? ??.
| |