网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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://bjjierui.cn/article/jsjjoc.html

其他资讯