c++ 卡片游戏

#includeusing namespace std;struct chainNode{int element;      //用来装牌的号码 chainNode* next; chainNode(int element, chainNode *n){this->element =element;this->next = n;}};class mylinkqueue{public:mylinkqueue();~mylinkqueue();int getsize();   //返回大小void pop();   //删除头元素int front();  //返回首元素 void push(int); //把元素加到队尾 private:int size;		chainNode* thefront;chainNode* theback;	  };//构造 mylinkqueue::mylinkqueue(){size = 0;thefront = NULL;theback = NULL;}//析构 mylinkqueue::~mylinkqueue(){chainNode *c=thefront;while(c!=NULL){c=c->next;delete thefront; thefront = c;} }//求大小 int mylinkqueue::getsize(){return size;}//删除 void mylinkqueue::pop(){if(thefront==NULL){return;}	 chainNode* nextNode = thefront->next;delete thefront;thefront = nextNode;size--;}//添加void mylinkqueue::push(int a){chainNode* newNode = new chainNode(a,NULL);if(size==0)thefront = newNode;else{theback->next=newNode;}theback= newNode;//newNode成为了尾size++; } //返回首元素int mylinkqueue::front(){return thefront->element;} int main(){int n;cin>>n;mylinkqueue q;//初始化 for(int i=1;i<n+1;i++){//	cout<<"i="<q.push(i); 		}//	cout<//	chainNode* a = q.getfront() ;int a=0;while(q.getsize ()>1){	//cout<<"丢掉"<q.pop();a=q.front() ;//	cout<<"丢掉"<q.pop() ;//	cout<<"把a插入 a="<q.push(a); }cout<<q.front() ;}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部