C#自定义堆栈进行回文检测的代码-创新互联

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

创新互联是一家专业提供新晃企业网站建设,专注与成都网站建设、网站建设、HTML5、小程序制作等业务。10年已为新晃众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

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

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:C#自定义堆栈进行回文检测的代码-创新互联
分享网址:http://myzitong.com/article/ccicdh.html