, . ( , , ).
':
;
;
.
Pascal. (, ). , '.
C- . ³ , (ᒺ) . , .
, ' , / . . , , .
:
;
;
;
;
( );
( );
;
.
. - , :
class Node
{
public:
char d;
Node *next;
Node (char dat = 0) { d = dat;next = 0;}
};
class List
{
public:
Node *pbeg, *pend;
List() { pbeg = 0;pend = 0;}
~List();
void add(char d);
int pos(char d);
int len();
char get(int num);
void concat(List lst2);
void print();
};
, , .
void List::add(char d) //
{ Node *pv = new Node(d);
if(!pbeg) {pbeg = pend = pv;}
else { pend->next = pv;
pend = pv;}
}
//
int List::pos(char d)
{ int p=0;
Node *pv = pbeg;
while(pv) { if(pv->d == d) return p;
p++; pv = pv->next;}
return -1;
}
int List::len() //
{ int p=0;
Node *pv = pbeg;
while(pv) { p++; pv = pv->next;
}
return p;
|
|
}
char List::get(int num) //
{ int i=0;
Node *pv = pbeg;
while(pv)
{ if (num==i) return pv->d;
i++; pv = pv->next;
}
}
void List::concat(List lst2) // ᒺ
{for(int i=0;i!=lst2.len();i++)
add(lst2.get(i));}
void List::print() // ³
{ Node *pv = pbeg;
cout << endl << " list: ";
while(pv)
{ cout << pv->d << " ";
pv = pv->next;}
cout << endl;
}
List::~List() //
{
if(pbeg)
{ Node *pv = pbeg;
while(pv) { pv = pv->next; delete pbeg; pbeg = pv;}
}
}
, List. - 'BETA' ; 'A', -, 2 ; - 'list' ; ᒺ - ; - '11' ; ᒺ - .
void main()
{ List l1;
l1.add('B');
l1.add('E');
l1.add('T');
l1.add('A');
l1.print();
cout<<" pos="<<l1.pos('A')<<endl;
cout<<" len="<<l1.len()<<endl;
cout<<" elem="<<l1.get(2)<<endl;
List l2;
l2.add('l');
l2.add('i');
l2.add('s');
l2.print();
l1.concat(l2);
l1.print();
List l3;
l3.add('1');
l3.add('1');
l1.concat(l3);
l1.print();
getch();
}