#include<iostream> using namespace std; template<class numtype> struct pnode { numtype date; pnode* p; pnode(numtype e) {p=NULL; date=e;} }; //山寨stack template<class numtype> class szStack { private: pnode<numtype>* head; public: void push(numtype e) { pnode<numtype>* point=new pnode<numtype>(e); point->p=head; head=point; } numtype top() { return head->date; } void pop() { pnode<numtype>* point=head; head=head->p; delete point; point=NULL; } bool empty() { if(head) return false; return true; } szStack() {head=NULL; } }; struct node { int x,y; }; int main() { node pp; int i; szStack<node>ss; for(i=1;i<99;i++) { pp.x=i+1; pp.y=i*2; ss.push(pp); } while(!ss.empty()) { pp=ss.top(); cout<<pp.x<<' '<<pp.y<<" "; ss.pop(); } cout<<"\n\n\n"; szStack<int>sint; for(i=1;i<99;i++) { sint.push(i); } while(!sint.empty()) { cout<<sint.top()<<" "; sint.pop(); } system("pause"); }
//
#include<iostream>
using namespace std;
template<class numtype>
struct pnode
{
numtype date;
pnode* p;
pnode(numtype e)
{date=e;p=NULL;}
};
template<class numtype>
class myQueue
{
private:
pnode<numtype>* head,*tail;
int size;
public:
void push(numtype e)
{
if(size==0)
{
head=tail=new pnode<numtype>(e);
}
else
{
tail->p=new pnode<numtype>(e);
tail=tail->p;
}
size++;
}
numtype front()
{
return head->date;
}
void pop()
{
pnode<numtype>* tempoint=head;
head=head->p;
delete tempoint;
tempoint=NULL;
size--;
}
bool empty()
{
if(size==0)
return true;
return false;
}
int getSize()
{
return size;
}
myQueue()
{
head=tail=NULL;
size=0;
}
};
struct node
{
int x,y;
};
int main()
{
node pp;
int i;
myQueue<node> ss;
cout<<ss.getSize()<<endl;
for(i=1;i<99;i++)
{
pp.x=i+1;
pp.y=i*2;
ss.push(pp);
}
cout<<ss.getSize()<<endl;
while(!ss.empty())
{
pp=ss.front();
cout<<pp.x<<' '<<pp.y<<" ";
ss.pop();
}
cout<<endl<<ss.getSize()<<endl;
getchar();
}