您好,登錄后才能下訂單哦!
在研發(fā)之余,將做工程過程中比較重要的一些內(nèi)容備份一下,如下的內(nèi)容內(nèi)容是關(guān)于C# 自定義堆棧進行回文檢測的內(nèi)容,希望對各朋友也有用。
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];
}
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。