//1、实现栈类//2、实现10进制到8进制的转换//2006 05 13#include <iostream.h>#include<string>class Node{public: int data; Node *next;};class Stack:public Node{ Node *Bottom; Node *Top; int SLen;public: void InitStack(); int Pop(); void Push(int e); bool StackEmpty();};void Stack::InitStack(){ Top=new Node; Bottom=Top; SLen=0;}int Stack::Pop(){ int e; Node *p; if(!(Top->next)) exit(0); else { p=Top; e=p->data; Top=p->next; delete p; SLen--; } return e;}void Stack::Push(int e){ Node* p=new Node; p->next=Top; p->data=e; Top=p; SLen++;}bool Stack::StackEmpty(){ if(SLen==0) return 1; else return 0;}void conversion(int N){ Stack s; s.InitStack();// cin>>N; while(N) { s.Push(N%8); N=N/8; } while(!s.StackEmpty()) { int e; e=s.Pop(); cout<<e; } cout<<endl;}//end conversionvoid main(){ conversion(10);}

评论