2021-10-02-《C#数据结构与算法》-学习笔记-P14-P17栈

总结
1.视频资源P14-P17:
https://www.bilibili.com/video/BV1gE41157pC?p=8&spm_id_from=pageDriver
2.学习内容:
1)栈与队列 P14;
数据结构:栈部分
2)数组栈 P15;
3)链表栈 P16;
4)数组栈与链表栈性能对比 P17。
3.2021/10/11回溯:
紫色红色笔均为回溯后增加
1)根据伪代码编写程序。

具体内容

P14 栈
1、什么是栈;
2、栈的应用。

在这里插入图片描述

P15 数组栈
1、栈通用接口;
2、创建数组栈类。

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    class Array1Stack<E>:IStack<E>
    {
        private Array1<E> array1stack;

        public Array1Stack(int capacity)
        {
            array1stack = new Array1<E>(capacity);
        }
        public Array1Stack()
        {
            array1stack = new Array1<E>();
        }

        public int Count { get { return array1stack.Count;} }

        public bool IsEmpty { get { return array1stack.IsEmpty; } }

        public E Peek()
        {
            return array1stack.GetLast();
        }

        public E Pop()
        {
            return array1stack.RemoveAtLast();
        }

        public void Push(E e)
        {
            array1stack.InsertAtLast(e);
        }

        public override string ToString()
        {
            return "Stack: " + array1stack.ToString() + "top";
        }
    }
}

P16 链表栈
1、创建链表栈类。

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    class Linklist1Stack<E>:IStack<E>
    {
        private Linkedlist1<E> linkedlist1stack;

        public Linklist1Stack()
        {
            linkedlist1stack = new Linkedlist1<E>();
        }

        public int Count { get { return linkedlist1stack.Count; } }

        public bool IsEmpty { get { return linkedlist1stack.IsEmpty; } }

        public E Peek()
        {
            return linkedlist1stack.GetFirst();
        }

        public E Pop()
        {
            return linkedlist1stack.RemoveAtFirst();
        }

        public void Push(E e)
        {
            linkedlist1stack.InsertFirst(e);
        }

        public override string ToString()
        {
            return "Stack: top " + linkedlist1stack.ToString();
        }
    }
}

P17 数组栈与链表栈性能分析
1、数组栈与链表栈时间复杂度理论分析;
2、数组栈与链表栈时间复杂度实际分析。

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值