return current->info;
};
char* list::read_element(int &k)
{
int i;
i=current_element(k);
if ((i<k)&&(i!=0))
cout<<"V spiske vsego "<<i<<" elmentov. Po etomu vmesto "<<k<<" elementa, functsia vozvrashchaet "<<i<<" element!!!\n";
k=i;
void list::init_list(int k, char* str)
if (k==0) return;
int f(2);
char* s;
s=new char[strlen(str)+7];
if (first!=NULL)
cout<<"Spisok ne pust!!!\n";
cout<<"Chto delat?(0/1/2)\n";
cout<<" 0)Otmenit initsializatsiu;\n";
cout<<" 1)Dopisat fonarnuu infomatsiu v konets spiska;\n";
cout<<" 2)Zamenit spisok novoi fonarnoi informatsyei.\n";
cin>>f;
if(f==0) return;
if(f==1) current=last;
if(f==2)
del_list();
first=new element[1];
first->info=new char[strlen(str)+3];
sprintf(first->info,"%s 1",str);
first->up=first->down=NULL;
current=last=first;
for (int j=f; j<=k; j++)
sprintf(s,"%s %d",str,j);
add_after(s);
return;
void list::print_list()
cout<<"Vmestimoe spiska:\n";
element* temp=first;
if (first==NULL)
cout<<"Spisok pust!!!\n";
do
temp=temp->down;
while (temp);
cout<<"\n";
int list::fput_list(char* s)
FILE* f;
if ((f=fopen(s,"w+"))==NULL)
cout << "Can not open file "<<s<<"\n";
return 0;
if (!first) fclose(f);
fputs(temp->info,f);
fputs("\n",f);
}
fclose(f);
return 1;
int list::fget_list(char* s)
int ff=2;
cout<<"Spisok ne pust!!!\nChto delat?(0/1/2)\n 0)Otmenit vostanovlenie iz faila;\n";
cout<<" 1)Vostanovit infomatsiu iz faila v konets spiska;\n";
cout<<" 2)Zamenit spisok informatsyei iz faila.\n";
cin>>ff;
if(!ff) return ff;
if ((f=fopen(s,"r"))==NULL)
cout<<"Can not open file "<<s<<"\n";
char str[255];
if(ff==1)
current=last;
char *sss;
if(ff==2)
while (fgets(str,256,f))
sss=new char[strlen(str)];
int j=0;
while(str[j]!='\n')
sss[j]=str[j++];
sss[j]='\0';
add_after(sss);
delete [] sss;
return ff;
#endif
#include "list_.h"
void main()
int n=16;
cout<<"Rozhdenie spiska...\n";
list s;
char a[255];
strcpy(a,"Seha");
s.print_list();
cout<<"\nVsego elementov v spiske: "<<s.num_list();
cout<<"\nTekuschiy element spiska: "<<s.num_current()<<'\n';
cout<<"Press <Enter> for go on...\n";
getchar();
cout<<"Skol'ko proinitsializirovat' elementov spiska?\nn=";
cin>>n;
cout<<"Initsialitsia spiska...\n";
s.init_list(n,a);
cout<<"\nTekuschiy element spiska: ";
cout<<s.num_current()<<'\n';
getchar();//clear iostream
cout<<"Kakoi element v spiske sdelat' tekeschim?\nn=";
s.current_element(n);
cout<<"\nVsego elementov v spiske: "<<s.num_list()<<"\nTekuschiy element spiska: "<<s.num_current()<<'\n';
cout<<"Skol'ko elementov dobavit'?\n";
for (int i=0; i<n; i++)
cout<<"Vvedite stroku dlja dobavlenija v spisok\n";
gets(a);
cout<<"Dobavlenie posle tekuschego...\n";
s.add_after(a);
cout<<"Delaem tekuschim sledujushiy element...\n";
s.next_element();
cout<<"Skol'ko eschje elementov spiska nuzhno dobavit'?\n";
cout<<"Dobavlenie do tekuschego...\n";
s.add_before(a);
for (int k,i=0; i<n; i++)
cout<<"Vvedite nomer elementa, na kakoe mesto nuzhno dobavit' novyi element\n";
cin>>k;
cout<<"Dobavlenie "<<k<<"-togo elementa...\n";
s.add_element(a,k);
cout<<"Skol'ko elementov udalit'?\n";
cout<<"Udalenie tekuschego...\n";
s.del_element();
cout<<"Skol'ko eschje elementov spiska nuzhno udalit?\n";
cout<<"Vvedite nomer elementa, kotoryi nuzhno udalit'\n";
cout<<"Udalenie "<<k<<"-togo elementa...\n";
s.del_element(k);
Страницы: 1, 2, 3, 4