cout<<endl;
for (int j=(p-1); j<n; j++)
MasP[j]=MasP[j+1];
MasP[n]=0;
n--;
}
}
////////////////////Save List/////////////////////
void SaveList(){
if (n==0) cout<<endl<<"List is empty."<<endl;
else{
for (int i=0; i<n; i++){
if (i%10==0) f<<endl;
f<<setw(3)<<*MasP[i];}
f<<endl;
}
}
///////////////////FindElement////////////////////
void FindElement(){
if (n==0) cout<<endl<<"List is empty."<<endl;
else{
cout<<endl<<"Input the value, which must be finded: ";
int a,s=0; cin>>a;
for (int i=0; i<n; i++){
if (*MasP[i]==a) {
cout<<endl<<(i+1)<<"-th element"<<" - "<<*MasP[i];
s=i;}}
if (s==0) cout<<endl<<"The existing list hasn't element with this value";
cout<<endl;
}
}
//////////////////SubWork(Sort)///////////////////
void SubMenu(){
if (n==0) cout<<endl<<"List is empty."<<endl;
else{
cout<<endl<<" Sub Menu:"<<endl;
cout<<" 1. Sort list by increase."<<endl;
cout<<" 2. Sort list by decrease."<<endl<<endl;
int i;
cout<<"Your choice: ";
do {
cin>>i;
if (i<1 || i>2) cout<<endl<<"Error! Try again : "<<endl;
}while (i<1 || i>2);
switch (i)
{case 1 : SortByIncrease(); break; //Increase
case 2 : SortByDecrease(); break; //Decrease
}
}
}
/////////////////SortByIncrease//////////////////
void SortByIncrease(){
int buf;
for (int i=0; i<(n-1); i++){
if (*MasP[i]>*MasP[i+1]){
SaveList();
buf=*MasP[i+1];
for (int j=0; j<(i+1); j++){
if (buf<*MasP[j]){
for (int q=i+1; q>j; q--)
*MasP[q]=*MasP[q-1];
*MasP[j]=buf;
break;
}//Incert place
}//for Incert place
}//Find unsorted element
}//for Find unsorted element
SaveList();
}
/////////////////SortByDecrease//////////////////
void SortByDecrease(){
int buf;
for (int i=0; i<(n-1); i++){
if (*MasP[i]<*MasP[i+1]){
SaveList();
buf=*MasP[i+1];
for (int j=0; j<(i+1); j++){
if (buf>*MasP[j]){
for (int q=i+1; q>j; q--)
*MasP[q]=*MasP[q-1];
*MasP[j]=buf;
break;
}//Incert place
}//for Incert place
}//Find unsorted element
}//for Find unsorted element
SaveList();
}
///////////////////Open File/////////////////////
void OpenList(char s[20]){
if (n!=0) {cout<<endl<<"Error! You have existing list.";
cout<<endl<<"Erase your prvious list ang try again."<<endl;}
else {
if (argcGlobal<3){
cout<<endl<<"Input file name: ";
char *FileName=new char[20];
cin>>FileName;
s=FileName;}
ifstream fo(s,ios::nocreate);
if (! fo) cout<<"File not found."<<endl;
else{
int b;
fo>>b;
for (int i=0; i<b; i++){
if (n==N) break;
MasP[n]= new int;
fo>>*MasP[n];
n++;
}
}//if (! fo)...
}
}
------------------------------------------------------------------- func.h
//Ïîäêëþ÷àåì ñòðàæè âêëþ÷åíèé.
#ifndef __func_h
#define __func_h
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string.h>
#include <time.h>
extern char foname[20];
//Ïðîòîòèïû ôóíêöèé.
void MakeNewList();
void AddElements();
void PrintList();
void DeleteElement();
void SaveList();
void EraseList();
void FindElement();
void SubMenu();
void SortByIncrease();
void SortByDecrease();
void OpenList(char s[20]=foname);
#endif
Список литературы
1. Лафоре Р. Объектно-ориентированное программирование в С++, 4-е изд. - СПб.: Питер, 2003. – 928 с.: ил.
2. Дейтел Х.М., Дейтел П.Дж. Как программировать на С++.. – М.: Бином, 1999. - 1024 с.
3. Страуструп Б. Язык программирования С++, 3-е изд. - СПб.; М.: Невский Диалект - Бином, 1999. - 991 с.
4. Керниган Б., Ритчи Д. Язык программирования Си.\Пер. с англ., 3-е изд., испр. - СПб.: "Невский Диалект", 2001. - 352 с.: ил.
Примечание 1.
Примечание 2.