有一个问题:"设单链表中存放n个字符,设计一个算法,使用栈判断该字符串是否中心对称!如xyzzyx既为中心对称字符串!!"
请问怎么设计算法???能详细说说吗??谢谢!!!
                     一名初学数据结构的学生

解决方案 »

  1.   

    把单链表压入栈A,同时得到字符串的长度,再建立一个栈B,从栈Apop全部字符的一半同时push到栈B,然后栈A和栈B同时pop比较不就可以了吗?
      

  2.   

    同意楼上:  if (! 链表长度 % 2 )
      {
           MessageBox("It's not!"); return;
      }
      CString  str;
      str = push( 链表长度 % 2 ); // 将前一半压站
      
      for(int i = 0; i < 链表长度 % 2; i++)
      {
           if( pop( i ) ! = string[ 链表长度 / 2 + i ] )  // string 是链表数据
           {
               MessageBox("It's not");  return;
           }
       }
       MessageBox("HO ! It is");
      

  3.   

    笔误!if ( 链表长度 % 2 != 0)
      {
           MessageBox("It's not!"); return;
      }
      CString  str;
      str = push( 链表长度 / 2 ); // 将前一半压站
      
      for(int i = 0; i < 链表长度 / 2; i++)
      {
           if( pop( i ) != string[ 链表长度 / 2 + i ] )  // string 是链表数据
           {
               MessageBox("It's not");  return;
           }
       }
       MessageBox("HO ! It is");
      

  4.   

    xyzyx是否为中心对称?
    如果是的话,那么楼上的可能只做了一半的工作。
      

  5.   

    HKer_007(伙计,拿杆烟来吃)不就是大侠吗!现场编程啊!
      

  6.   

    学习数据结构HKer_007(伙计,拿杆烟来吃)用MFC来做有点过了!
    Win32 Console就行了!xfr_1982(独孤一笑) 你会建栈吗?呵呵!