Error:

Debug Assertion failed: Expression: BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

Code:

#include "stdafx.h"
#include<iostream>
#include<stdlib.h> 
#using <System.dll>
#include< math.h>
#include< time.h>
#include<List>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;
int someSize=2000;
# define SIZE 20


class queue
{
    int aMsg[SIZE];
    int front;
    int rear;
public:
    queue();
    ~queue();
    void insertMessage(int i);
    int removeMessage();
    int isempty();
    int isfull();
    void displayitem();
};

queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
delete []aMsg;
}
void queue::insertMessage(int i)
{
if(isfull())
{
     Console::WriteLine("******Queue is FULL !!!No insertion allowed further.******");
    return;
}
aMsg[rear] = i;
rear++;
}
int queue::removeMessage()
{
if(isempty())
{
    Console::WriteLine("******Queue Empty !!!Value returned will be garbage.******");
    return (-9999);
}

return(aMsg[front++]);
}
int queue::isempty()
{
if(front == rear)
    return 1;
else
    return 0;
}
int queue::isfull()
{
if(rear == SIZE)
    return 1;
else
    return 0;
}
void queue::displayitem()
{
   if(isempty()) 
     Console::WriteLine("****Empty*****");
      else
        for(int i=front; i!=rear; i++)
              Console::WriteLine("the queue is having item {0}", aMsg[i]);
  }



int main(array<System:: String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    queue q;
    q.insertMessage(3);
    q.insertMessage(4);
    Console::WriteLine("the queue removed item {0}",q.removeMessage());
    //q.displayitem(); 
    return 0;
}

Edited 3 Years Ago by pyTony: fixed formating

You have way too many things going on at once.
This code should not even compile.

Start with the first error.

Also figure out what the includes do.

#include "stdafx.h"
#include <iostream>
#include<stdlib.h>
//#using <System.dll>
#include <math.h>
#include <time.h>
//#include<List>
using namespace System; 
using namespace System::Collections::Generic; 
using namespace System::Linq;

Edited 4 Years Ago by thines01: typo

Thank you very much for your reply. Sorry! in fact that one was copied from previously running code. Do you think "Include" statement really affects. But I wanna know in logic where the error is and it is giving debug assertion problem.

What I'm saying is that this code will produce compiler errors that you are ignoring and attempting a run anyway. Compiling is the first "test" of the code. There is no need to attempt to satisfy the debugger when the compiler is not happy.

I created a project and inserted most of this code into it.
The only includes and namespaces I kept were:

#include "stdafx.h"
using namespace std;
using namespace System;

And I changed the destructor to NOT delete something that was not dynamically created

queue::~queue()
{
   //delete []aMsg;
}

I compiled it under warning level 4 with warnings as errors.
It compiled and ran with the message "the queue removed item 3"

Edited 4 Years Ago by thines01: added code

Hi, Thanks That's the problem I am not doing good enough to find the root of the issue. Need help please

Please see the last post (I edited it).
Also, my last two sentences should have said:

I compiled it under Warning Level 4 (treating warnings as errors).
It compiled with no errors or warnings and ran with the message "the queue removed item 3"

Edited 4 Years Ago by thines01: clarity

It does not need to delete that array aMsg.
aMsg was not created with "new" (dynamically), so you don't delete it.

You should also consider a couple of other changes that will enhance your future coding. One is the use of the bool instead of int when determining true or false.
...and the use of less code to represent the same action:

bool queue::isempty()
{
   return (front == rear);
}

bool queue::isfull()
{
   return (rear == SIZE);
}

Also, keep it simple and avoid printing from inside the class.
If -1 is invalid, you don't need -9999
And if you get the -1, you don't really need to see a message coming from inside the class -- it should be shown from outside the class. You might want to use this from a WinForm or something else that does not use Console::WriteLine() some day;

int queue::removeMessage()
{
   if(isempty())
   {
      return -1;
   }

   return aMsg[front++];
}

//...from main()
   if(-1 == q.removeMessage())
   {
      Console::WriteLine("Queue is empty");
   }
This question has already been answered. Start a new discussion instead.