队列操作的实现

  # 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);
  }

上一篇:循环顺序队列


下一篇:java集合框架的三大类区别,HR的话扎心了