我的回文计划无效 [英] My palindrome program is not working

查看:73
本文介绍了我的回文计划无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个程序来检查一个字符串是否是回文但是在我输入后它给出错误

例如如果我给雷达字

它应该显示Palindrome

但是它没有正常工作没有语法错误请帮助



我是什么尝试过:



I have tried to make a program that checks for a string whether it is a palindrome or not but it is giving error after I give input
For Example if i give radar word
it should display Palindrome
but it is not working properly there are no syntax error please help

What I have tried:

#include<iostream>
using namespace std;
class node{
	public:
	char v;
	node *next;
    node *prev;
};
class queue{
	node *front,*rear;
	int size;
	public:
	queue()
	{
		front=new node();
		rear=NULL;
		size=0;
	}
	void enqueue(char a)
	{
		node *newnode=new node();
		newnode->v=a;
		if(rear!=NULL)
		{
			rear->next=newnode;
			rear->prev=front->next;
			newnode->next=NULL;
			newnode->prev=rear;
			rear=newnode;
		}
		else
		{
			front->next=newnode;
			front->prev=NULL;
			newnode->next=NULL;
			newnode->prev=front;
			rear->prev=front;
			rear=newnode;
		}
		size++;
	}
	int si()
	{
		return size;
	}
	int check()
	{
		int count;
		node *p=front->next;
	    	while(p!=NULL)
	    	{
	    		if(p->v==rear->v)
	    		{
	    			count++;
	    		}
	    		p->next;
	    		rear->prev;
	    	}
	    	return count;
	    
	}
};
int main()
{
	queue q1;
		int s,num;
	cout<<"Enter size of string :";
	cin>>s;
		char a[s],n;
	cout<<"Enter string :";
	cin>>a;
	for(int i=0;i<s;i++)
	{
		n=a[i];
		q1.enqueue(n);
	}
	
	num=q1.check();
	if(s%2==1)
	{
	if(num==(s-1))
	{
		cout<<"Palindrome"<<endl;
	}
	else
	{
		cout<<"not a Palindrome";
	}
    }
    else
    {
    	if(num==s)
	{
		cout<<"Palindrome"<<endl;
	}
	else
	{
		cout<<"not a Palindrome";
	}
    }
	return 0;
}

推荐答案

这是你的功课,也不是我们的功课 - 让它正常工作是这项任务的一部分。

所以,它取决于你。

在函数的第一行放置断点,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
This is your homework, nor ours - and getting it working is part of the task.
So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


Quote:

但它给出错误



哪条错误消息?



有一个工具专门用来帮助程序员理解他们的代码在他们没有做到的时候真正做的事情,试一试。



有一个允许您查看代码正在执行的工具,其名称为调试器。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与什么进行比较应该这样做。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


Which error message ?

There is a tool made especially to help programmer to understand what their code is really doing when it don't do what they expect, give it a try.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于我的回文计划无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆