资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

C#自定义堆栈进行回文检测的代码

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

创新互联主要从事网站制作、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务许昌,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

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];  
    }  
}  

}


文章名称:C#自定义堆栈进行回文检测的代码
本文来源:http://cdkjz.cn/article/jsjjoc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220