4
: . . . | : 3- -1644 . . |
2016
4 (4 .).
: .
: . .
: :
;
;
.
. . .
:
1) .
2) .
3) ( .)
4) 1.
:
1) .
2) .
3) ++.
4) .
5) .
6) .
ʳ | ||||
Int+int |
˳
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
struct sp{
int p1, p2;
sp *pnt;
};
sp *pt, *ptb;
void stvor(int n), vived(sp **firstPointer), delOb(sp **firstPointer);
int main()
{
int key(0);
while(1)
{
cout<<setfill('=')<<setw(144);
cout<<"\n1. Create stack\t\t2. Print to monitor\n3. Delete element\t4. Exit\n";
cout<<"Please input key = "; cin>>key;
cout<<setfill('_')<<setw(81);
cout<<'\n';
switch(key)
{
case 1: stvor(11); break;
case 2: vived(&ptb); break;
case 3: delOb(&ptb); break;
case 4: exit(1); break;
default: cout<<"Error!\n";
}
}
return 0;
}
void stvor(int n)
{
ptb = new sp;
pt = ptb;
for(int i=1;i<n;i++)
{
pt->p1 = rand()%100-50;
pt->p2 = rand()%100-50;
pt->pnt = new sp;
pt = pt->pnt;
}
pt->p1 = rand()%100-50;
pt->p2 = rand()%100-50;
pt->pnt = NULL;
cout<<"Stack create!\n";
}
void vived(sp **firstPointer)
{
pt = *firstPointer;
int i(0);
if(pt){
cout<<"\n###\tatribut[1]\tatribut[2]";
cout<<"\n___\t__________\t__________\n";
while(pt)
{
i++;
cout<<i<<'\t'<<pt->p1<<"\t\t"<<pt->p2<<'\n';
|
|
pt = pt->pnt;
}
}
else cout<<"Stack not create!\n";
}
void delOb(sp **firstPointer)
{
pt = *firstPointer;
if(pt){
sp *pt1 = new sp;
while(pt->pnt!=NULL)
{
pt1 = pt;
pt = pt->pnt;
if(pt->pnt == NULL)
{
delete pt;
pt = pt1;
pt->pnt = NULL;
}
}
cout<<"Last element delete!\n";
}
else cout<<"Delete element error, but stack not create!\n";
}
:
. , , . , 2 int. : 11 ; ; ; .