C++ ::  Recursive Palindrome Test With Merge Sorting

May 28, 2013

My assignment is to make a program that tests whether something is a Palindrome or not using a recursive function. Also, in order to test what type the Palindrome is (if it is indeed a palindrome) I'll need to merge sort it. Now alphabet characters, spaces, and numbers are all allowed, as long as the spaces line up with the spaces in the original input. And yes this is user inputted. I can show you what I've got so far and then I'll tell you what my problem is.

#include <iostream>
#include <istream>
#include <string>
#include <string.h>
#include <conio.h>
using namespace std;
/************To Test if Palindrome*******************/
bool IsPalindrome(char *str, int size) {
if( str[0] == str[size-1]);

[Code] .....

Now my problem is that I can't seem to get the test to work correctly. Since the word is user inputted I don't have any way of knowing the size so that kind of complicates it a little bit. The other thing is I was told by my professor that I need a boolean flag to make it work, and I need to set the value to the return of the IsPalindrome function. I'm not sure how to do that. I also don't haven't been able to add in the MergeSort yet, so the Order and Type don't really work correctly because I'm not sure how to get int len for it. (len is length)

View 3 Replies


ADVERTISEMENT

C :: Implementing Recursive Merge Sort - Forbid Warning

Jul 8, 2013

I am trying to implement a recursive merge sort, and I've just barely begun. I am getting some warnings:

merge_sort.c:15: warning: ISO C90 forbids variable-size array 'left'
merge_sort.c:15: warning: ISO C90 forbids mixed declarations and code

Code:
#include <stdio.h>
#include <string.h>

static void
merge_sort(int *a, int n)

[Code] ....

I am using gcc 4.2.1 and I am compiling with -Wall and -pedantic.

View 6 Replies View Related

C/C++ :: Sorting Deck From File With Merge Sort

Nov 27, 2014

I'm trying to sort a deck from file with merge sort.I have all my code working except merge sort function .

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int temp;
int br = 1;

[Code] ....

View 10 Replies View Related

C :: Merge Sorting The Linked Lists - Runtime Error

Aug 10, 2013

The following program throws runtime error.

Code:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;

[Code] .....

View 3 Replies View Related

C :: Sorting List Of Students Based On Their Test Scores

Jan 18, 2014

I need to sort these students based on their test scores.

My biggest problem is with my sort function. I am not sure of the syntax to call the items the proper way. I also don't know how to call the function properly as I know that i can't pass a int to a struct. Also not sure about the z malloc. Just threw that one in there.

Code:
struct student{
int id;
int score;
};
void sort(struct student* students, int n){
/*Sort the n students based on their score*/

[Code] ....

View 5 Replies View Related

C/C++ :: Seg Fault In Recursive Sorting Algorithm

Apr 23, 2015

So I am working on a dual pivot quicksort, I can correctly sort the array the first time around however in the main it is called again on the sorted array and in the function I get a seg fault at line 17 in sort.cpp, for the life of me I cant figure it out as the values are the same when I pass it in the first time. Here is the code:

main1.cpp

#include <iostream>
#include "movement.h"
#include "sort.h"
using namespace std;
int main() {
const int size = 10;
T array[size] = {6, 5, 1, 8, 4, 7, 2, 9, 6, 3};

[Code] ....

View 4 Replies View Related

C :: Array Sorting Program That Works With Recursive Function

Mar 10, 2013

i want to write an array sorting program that works with recursive function.but i can not do it.

my algorithm

Recursive
find the min value
find the min value and save it
find the min value and save it and remove it from loop
put the rest in loop again
find the min value again
..
...

i didnt write the function because i dont know how will it work

Code:

#include<stdio.h>
#include<stdlib.h>
#define s 5
void main() {
int a[s]={25,3,2,4,1},c[s]; // c[s] for new sorting
int i,ek,j; //ek = min

[Code]....

View 7 Replies View Related

C++ :: How To Find Palindrome

Dec 2, 2013

how to get this program to find the palindrome? Here is my program:

#include <iostream>
#include <string>
using namespace std;
using std::string;

[code].....

View 2 Replies View Related

C :: Checking Whether A String Is Palindrome Or Not

Nov 4, 2013

Everything seems to be correct from my perspective. heres the program: Code: /*c program to check whether a string is palindrome or not*/

#include<stdio.h>
#include<string.h>

int main(void) {
char str[30];
int i,j,flag=0;

[Code] .....

View 1 Replies View Related

C++ :: Identifier String Value Is Palindrome Or Not

Feb 9, 2013

here is my code, the issue is its not determine if the value is a palindrome or not.

// unit 5b.cpp : Defines the entry point for the console application.
//
// How to read a file
// identify the string if its a palindrome or not
//

#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <fstream>

[Code] .....

View 1 Replies View Related

C++ :: Check A String To Be Palindrome

Apr 23, 2014

I am trying to check a string to be a palindrome. I have tried using for loop but I am looking for most efficient way.

View 5 Replies View Related

C++ :: Palindrome Loop Error

Oct 5, 2013

My loop keeps getting an error and I don't know why?

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main (){
int loop;
string word;

[Code] ....

View 3 Replies View Related

C++ :: CPP Program To Check Whether A Number Is Palindrome Or Not?

Feb 12, 2014

I could not find the mistake in this program....

Code:
//cpp program to check whether a number is palindrome or not
#include<iostream.h>
#include<conio.h>
//the class
class palindrome

[Code] ....

View 4 Replies View Related

C++ :: Program That Checks Whether A String Is Palindrome

Apr 27, 2014

Write a program that checks whether a string is a palindrome. A palindrome is a word, phrase, orsequence that can be read the same backward and forward.

Code:
#include<iostream>
#include<string>
using namespace std;
int main(){

[Code] .....

View 2 Replies View Related

C :: Program To Check If Phrase Is Palindrome Or Not

Nov 8, 2013

I get this error..In function 'main':

p6.c.text+0x6a): undefined reference to 'palindromeness'
collect2: 1d returned 1 exit status

This is program is suppose to check if a phrase is a palindrome or not.I need to write a function definition for _Bool palindromeness(char str[])but I am having a tough time figuring that part out. I am brand new to programming..this is my first class and I am just learning arrays and pointers.

View 4 Replies View Related

C :: Function Which Can Recognize Whether A Word Is Palindrome

Jun 24, 2013

I'm trying to write a function which can recognize whether a word is a palindrome. if it's the case , it must return 1 on screen, otherwise 0. This is the code which return 0 even in case of a palindrome...

Code:
int IsPalindrom(char String[]){
int i,l;
int counter=0;
for(i=0;;i++){ //counts the number of array elements

[Code] ....

View 9 Replies View Related

C++ ::  Palindrome Program Compile Error

Jan 16, 2014

Here is the code which I wrote in Turbo C++...its giving errors..

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
voidmain() {
clrscr();

[code]....

View 8 Replies View Related

C++ :: Program To Check Whether Or Not A String Is Palindrome

May 20, 2013

So I've been tasked with creating a program that checks to see whether or not a string is a palindrome. It has to remove whitespace, punctuation, and capitalization for obvious reasons. Getting some errors which I'm not sure how to correct.

On an unrelated note, while programming in the console, my cursor has turned into a gray box and replaces characters when typing, instead of pushing them forward, etc. How do I return it to normal?

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
bool isPalin(string& palin);
string cleanUp(string& palin);

[Code] .....

View 7 Replies View Related

C/C++ :: Palindrome Function Only Return False?

Apr 29, 2015

I have a text file that consists of:

1457887541
Madam
Able was I ere I saw Elba
Straw? No, too stupid a fad. I put soot on warts.
Class is cancelled today

And all of them are returning false as a palindrome and am not sure why that is so.

bool isPalindrome(const char *input){
int first = 0;
int last = strlen(input) - 1;

//begin loop to compare first position with last
while(last > first){

[Code] .....

View 3 Replies View Related

C++ :: Palindrome - String Subscript Out Of Range

Jun 13, 2014

I am trying to create a simple palindrome program. I get the error string subscript out of range. I believe the error is either in the while or for loops.

#include <cctype>
#include <string>
#include <iostream>
using namespace std;
//cleans string, converts to lower
bool cleanTolower(const string& s);

[Code] ....

View 2 Replies View Related

C/C++ :: Reverse A String And State If It Is A Palindrome

Mar 28, 2015

I am supposed to take the three string lines from a text file and then individually reverse them and state whether or not they are a palindrome. I have the three lines from the text file into string variables already but I am not sure on how to reverse them and then see if they are the same reversed(palindrome)

Here is my code so far -->

#include <iostream>
#include <string>
#include <cctype>

[Code].....

EDIT: Ignore line 123 and down in the code. That was merely test code and will not be used.

View 7 Replies View Related

C/C++ :: Find Out Whether A String Can Form A Palindrome Or Not

Sep 25, 2014

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void findPalind(char *arr) {
int i,j,n,odd,flag=0,count[26]={0};

[Code] ....

This question was asked in Hackerrank. [URL] ....

I am able to get correct output upto a input of 50000 character string, but not for 100000 character string.

View 12 Replies View Related

C/C++ :: Palindrome Program - Cstrings Using Strtok Function

Feb 28, 2014

I had an assignment to do a palindrome program but im stuck in this part.

"This c-string will be sent to a function that will remove all spaces and punctuation marks from its c-string as well as change any uppercase letters to lowercase. Use string tokens to eliminate the spaces & punctuation marks. Make sure you include the NULL as you concatenate the tokens into a c-string. Then copy back into the original c-string for the pass by reference."

void tokenptr(char drome[]) {
char *token;
size_t i;
token = strtok(drome, " ,.!:;?");
while (token != '') {

[Code] .....

I'm pretty sure I did that part except how can i pass this cstring back to main? We really haven't even touched much of pointers except to use strtok().

View 2 Replies View Related

C++ :: Identifying Palindrome Words - Running Into Segmentation Fault

Jul 16, 2013

I have written this program with the intention of identifiying palindrome words. Why I am running into a segmentation fault ?

Code:
#include <vector>
#include <iostream>
#include <string>
bool is_palindrome ( const std::string & s )

[Code] .....

View 6 Replies View Related

C :: How To Count And Display Palindrome Words In A Randomized Letters

Oct 11, 2013

how to count and display the palindromes in this randomized letters:

this is my program but it only prints randomized letters and can't count the palindromes words and display it:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code].....

View 2 Replies View Related

C++ :: Palindrome That Takes A Vector Parameter And Returns True Or False

Apr 26, 2014

Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

Code :
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);

[Code] .....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved