其他分享
首页 > 其他分享> > 队列操作的实现

队列操作的实现

作者:互联网

  # define _CRT_SECURE_NO_WARNINGS
  #include<stdio.h>
  #include<iostream>
  using namespace std;
  typedef struct SqQueue {
	  int* base;
	  int front;//头指针
	  int rear;//尾指针
  }SqQueue;
  //初始化
  void queueInit(SqQueue *ps) {
	  ps->base = new int[100];
	  if (ps == NULL) {
		  cout << "失败" << endl;
	  }
	  else cout << "成功" << endl;
	  ps->front = ps->rear = 0;
  }

  //入队
  void queuePush(SqQueue *ps,int x) {
	  ps->base[ps->rear]=x;
	  ps->rear++;
  }
  //出栈
  void queuePop(SqQueue* ps) {
	  ps->rear--;

  }


  //遍历栈
  void PrintStack(SqQueue ps) {
	  while (ps.front!=ps.rear)
	  {
		  cout << ps.base[ps.rear-1];
		  ps.rear--;
	  }
	  cout << endl;
  }
  int main() {
	  SqQueue s;
	  queueInit(&s);
	  queuePush(&s, 1);
	  queuePush(&s, 2);
	  queuePush(&s, 3);
	  queuePush(&s, 4);
	  PrintStack(s);
	  queuePop(&s);
	  PrintStack(s);
  }

标签:ps,队列,SqQueue,实现,int,base,操作,void,rear
来源: https://blog.csdn.net/qq_53965368/article/details/121089913