博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 自定义堆栈进行回文检测的代码
阅读量:6967 次
发布时间:2019-06-27

本文共 1569 字,大约阅读时间需要 5 分钟。

在研发之余,将做工程过程中比较重要的一些内容备份一下,如下的内容内容是关于C# 自定义堆栈进行回文检测的内容,希望对各朋友也有用。

using System;

using System.Collections;

namespace CStack

{
class Program
{
static void Main(string[] args)
{
CStack alist = new CStack();

string ch;          string word = "上海自来水来自海上";          bool isPalindrome = true;          for (int x = 0; x < word.Length; x++)          {              alist.Push(word.Substring(x,1));          }          int pos = 0;          while (alist.Count > 0)          {              ch = alist.Pop().ToString();              if (ch !=word.Substring(pos,1))              {                  isPalindrome = false;                  break;              }              pos++;          }          Console.WriteLine(isPalindrome);      }  }  public class CStack  {      private int p_index;      private ArrayList list;      public CStack()      {          list = new ArrayList();          p_index = -1;      }      public int Count      {          get { return list.Count; }      }      public void Push(object item)      {          list.Add(item);          p_index++;      }      public object Pop()      {          if (0 > p_index)          {              return null;          }          object obj = list[p_index];          list.RemoveAt(p_index);          p_index--;          return obj;      }       public void Clear()      {          list.Clear();          p_index = -1;      }      public object Peek()      {          if (p_index < 0)          {              return null;          }          return list[p_index];      }  }

}

转载于:https://blog.51cto.com/14101311/2325772

你可能感兴趣的文章
springmvc的过滤器和拦截器
查看>>
jQuery.each(object, [callback])数组对象操作--jQuery 对象访问 $().each(callback)
查看>>
树的存储结构 - 数据结构和算法41
查看>>
c3中基本动画
查看>>
按钮动画
查看>>
js练习题
查看>>
python ------- 文件处理之增删改查-------作业
查看>>
python 全栈 day03 计算机网络基础 -- 摘要
查看>>
类的一点点知识
查看>>
iOS - Swift Enumerations or how to annoy Tom
查看>>
Hibernate save()与persist()区别
查看>>
MongoDB给数据库创建用户
查看>>
linux下vim对于意外退出的文档的再次开启
查看>>
POJ 3683 2SAT
查看>>
如何替换B字段内包含A字段的那部分内容
查看>>
Objective-C Runtime 运行时
查看>>
常见的医学影像数据格式
查看>>
Vue Study [1]: Vue Setup
查看>>
Android 适配器
查看>>
mybatis三种传值方式
查看>>