2 Replies - 4098 Views - Last Post: 13 December 2008 - 08:45 PM Rate Topic: -----

#1 Altemia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 08

error C2061: syntax error : identifier 'intDequeStack'"

Posted 13 December 2008 - 07:34 PM


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//addons
#include <iostream>
#include <stack>
#include <ctime>
#include <list>
#include <vector>
//using namespace std;
using std::cout;
using std::endl;
//

#define N 8	
#define STMAX N*N

//int	 stack[STMAX];
int	 stp = 0;

int	 board[N][N];
int	 x,
		y,
		newx,
		newy,
		move_number,
		move_type;

template< typename T > void push(int v, T &stackRef);
template< typename T > int pop( T &stackRef );
template< typename T > int  top( T &stackRef );
template< typename T > void retract_move (T &stackRef);
int stack_empty();
int stack_full();

int main () {
	//addons
	std::stack<int> intDequeStack;
	//
	int p=0;
	unsigned long t;
	double time;

	int  move_valid ();
	void print_board();
	void try_move (int);
//addons
void push(int v, intDequeStack);
	pop( intDequeStack);
	top( intDequeStack);
//
//	void push(int v);
//	int pop();
//	int top();
	int stack_empty();
	int stack_full();

	board[0][0] = 1;

	move_number = 2;
	move_type = 0;
	newx = x = 0;
	newy = y = 0;

//  insert prior to the code you want to time
	t = clock();

	do {

		do {
			while (move_type == 8) {
			retract_move (intDequeStack);
			}
			move_type++;
			try_move (move_type);
		} while (!move_valid ());

		p++;
		push (move_type);
		x = newx;
		y = newy;
		move_type = 0;
		board[x][y] = move_number++;
		if(move_number> N*N) 
			print_board();
	} while (move_number <= N*N);

//  insert after to the code you want to time
	  time = ((double)(clock() - t)) / CLOCKS_PER_SEC;
	printf ("\n\nTime taken = %6.1f secs.\t %d pops\n\n\n", time, p);

}

void print_board()
{
	int i,j;

	printf("\n\n\n");

	for(i=N-1; i>=0; i--) {
		for(j=0; j<N; j++)
			printf("\t%d", board[j][i]);
		printf("\n\n");
	}
}


int	 move_valid () {
			return ((newx >= 0) && (newx < N) &&
			(newy >= 0) && (newy < N) &&
			(board[newx][newy] == 0));
}

void try_move (int mt) {
	switch (mt) {
	case 1: 
		newx = x + 1;
		newy = y + 2;
		break;
	case 2: 
		newx = x + 2;
		newy = y + 1;
		break;
	case 3: 
		newx = x + 2;
		newy = y - 1;
		break;
	case 4: 
		newx = x + 1;
		newy = y - 2;
		break;
	case 5: 
		newx = x - 1;
		newy = y - 2;
		break;
	case 6: 
		newx = x - 2;
		newy = y - 1;
		break;
	case 7: 
		newx = x - 2;
		newy = y + 1;
		break;
	case 8: 
		newx = x - 1;
		newy = y + 2;
		break;
	default: 
		printf ("Illegal move type %d in try_move", move_type);
		exit (1);
	}
}


template< typename T > void retract_move (T &stackRef) {
int mtype;
	if (!stack_empty())
	move_type = pop(intDequeStack);
	else
	printf (" exiting\n\n"), exit (-1);
	board[x][y] = 0;

mtype =(move_type+4)%8;
if (mtype==0)mtype=8;
	try_move (mtype);
	x = newx;
	y = newy;
	move_number--;
}


template< typename T > void push(int v, T &stackRef)
{
	//stack[stp++] = v;
	stackRef.push(v);
}

template< typename T > int pop(T &stackRef)
{
	//return stack[--stp];
	return stackRef.pop;
}

template< typename T > int top(T&stackRef)
{
	//return stack[stp-1];
	return stackRef.top();
}

int stack_empty()
{
	return stp == 0;
}

int stack_full()
{
	return stp == STMAX;
}



Wasn't sure whether to paste the entire code or not but I went for gold. :)

"tours 8 - 8.cpp(52) : error C2061: syntax error : identifier 'intDequeStack'"

This is the error I get, I'd much appreciate anyone who could fix or explain to me how to fix this problem. :D

Is This A Good Question/Topic? 0
  • +

Replies To: error C2061: syntax error : identifier 'intDequeStack'"

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4318
  • View blog
  • Posts: 12,100
  • Joined: 18-April 07

Re: error C2061: syntax error : identifier 'intDequeStack'"

Posted 13 December 2008 - 08:25 PM

Lets tackle a few issues here...

1) When you call a function you don't put the return type on the front. Nor do you put the data types in front of parameters you are passing to your function. I am referring to this line in particular...void push(int v, intDequeStack); inside your main function. I can only assume you are trying to call push there because it is not going to be a prototype because you already have that one defined up top.

So remove the void on the front and the "int" before v.

2) You haven't defined "v" to use in that push function. So you might want to declare it, give it a value and then send it to push to be pushed onto the stack.

3) It appears you have some prototypes down in your main function. Put those up with the rest of them. I am referring to these...

    int  move_valid ();
    void print_board();
    void try_move (int);



4) You can get rid of these in main because either they were prototypes that you have up above and forgot to remove or you are trying to make calls to them... either way you are not using them properly right now so no need to have them in main. You are going to be calling those functions from your other functions to determine if there are elements to pop or if you can push any more onto the stack.

// These are from main()
    int stack_empty();
    int stack_full();



5) Speaking of stack_empty and stack_full... you have them returning boolean values in the return statement but your return types are "int". While a bool can convert to an int, you should be returning bool on both functions, not int. Only makes sense right? Is stack empty? True or false. Is stack full? True or false.

6) Your pop function is not right. If you lookup a stack's pop method, you will see it doesn't return anything. It is a void function. So you can't have it directly in the return statement. What you need to do is get the "top" value first, pop() the stack second and return the value that was from top. Also make sure you check for being empty

template< typename T > int pop(T &stackRef)
{
    if (!stackRef_empty()) {
         int storedValue = stackRef.top();
         stackRef.pop();
         return storedvalue;
    }
    return -1; // Stack was empty, return some bogus value
}



Notice I also put parenthesis on the stackRef.pop() method. Don't forget those. ;)

7) In your top() function you return the top value from the stack. That is all fine and dandy... unless the stack is empty. Make sure you check the stack for being empty before you try to access top or pop. Just like we did in point 6 above.

8) In your outer do loop within main you have the line push (move_type); Remember, push takes two values for your function. The value and then the stack. NOT just one parameter.

Correct these and see what else you get. The program will still have issues but at least you will be in much better shape than you were before.

Enjoy!

"At DIC we be pop and push fixing code ninjas... we pop people until they push up daisies." :snap:
Was This Post Helpful? 0
  • +
  • -

#3 Altemia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 08

Re: error C2061: syntax error : identifier 'intDequeStack'"

Posted 13 December 2008 - 08:45 PM

View PostMartyr2, on 13 Dec, 2008 - 07:25 PM, said:

"At DIC we be pop and push fixing code ninjas... we pop people until they push up daisies." :snap:


Indeed you are lad. :D
I do believe I can sort it now.
Onto the next task of changing the code to work with a linked list apparently.
:)
Thank you!
Thank you!!
Thank you!!!
Thank you!!!!

Dave
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1