ADT(抽象数据类型):泛泛的说,就是将类(数据类型)进行高度抽象.着重于他做了什么而忽略了他是怎么做的.
即下面两类用链表分别模拟栈(Stack)和队列(Queue).
栈: FILO先进后出.拥有push(入栈)和pop(出栈)
队列: FIFO先进先出.拥有insert(入列)和remove(出列).
ADT即是将链表方法进行封装.让使用者只关心本身方法使用,而不关心具体的实现方式.
模拟的代码分别如下:
(一)栈模拟
);
        theStack.displayStack();
        theStack.pop();
        theStack.pop();
        theStack.displayStack();
    }
}
执行结果:先进后出
Stack (top ---> bottom){40.0}{20.0}
Stack (top ---> bottom){
80.0}{60.0}{40.0}{20.0}
Stack (top ---> bottom){
40.0}{20.0}
(二)模拟队列
);
        theQueue.displayQueue();
        theQueue.remove();
        theQueue.remove();
        theQueue.displayQueue();
    }

}
执行结果:先进先出
Queue (front ---> rear){20.0}{40.0}
Queue (front ---> rear){
20.0}{40.0}{60.0}{80.0}
Queue (front ---> rear){
60.0}{80.0}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-08-10
  • 2022-02-19
  • 2021-09-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案