Guest_imported
New member
- Jan 1, 1970
- 0
I am new at this game and was requesting some help from a pro. I cant figure out these errors while debugging. I fixed most of them but there are a few left. Thanks for the help.
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
struct queueNode
{ /*self-referential structure*/
char data;
struct queueNode *nextPtr;
};
typedef struct queueNode QueueNode;
typedef QueueNode *QueueNodePtr ;
/* function prototype*/
void printQueue ( QueueNodePtr );
int isEmpty( QueueNodePtr);
char dequeue( QueueNodePtr *, QueueNodePtr * );
void enqueue( QueueNodePtr *, QueueNodePtr *, char );
void instructions (void);
int main()
{
QueueNodePtr headPtr = NULL;
QueueNodePtr tailPtr = NULL;
int choice;
char item;
instructions ();
printf("?"
scanf("%d", &choice );
while ( choice !=3 )
{
switch( choice )
{
case 1:
printf( "Enter a character: "
scanf("\n%c", &item );
enqueue( &headPtr, &tailPtr, item );
printQueue ( headPtr );
break;
case 2:
if ( !isEmpty( headPtr ) )
{
item = dequeue( &headPtr, &tailPtr );
printf("%c has been dequeued.\n", item );
}
printQueue ( headPtr );
break;
default:
printf( "Bad Choice. \n\n" );
instructions();
break;
}
printf("?"
scanf("%d", &choice );
}
printf(" End of run.\n"
return 0;
}
void instructions (void)
{
printf("Enter your choice:\n"
" 1 to add an item to the queue\n"
" 2 to remove an item from the queue\n"
" 3 to end\" );
}
void enqueue ( QueueNodePtr *headPtr, QueueNodePtr *tailPtr,char value)
{
QueueNodePtr newPtr;
newPtr = malloc ( sizeof( QueueNode) );
if ( newPtr != NULL)
{
newPtr->data = value;
newPtr->nextPtr = NULL;
if ( isEmpty( *headPtr ) )
*headPtr = newPtr;
else
( *tailPtr )->nextPtr = newPtr;
*tailPtr = newPtr;
}
else
printf(" %c not inserted. No memory available.\n",value);
}
char dequeue ( QueueNodePtr *headerPtr, QueueNodePtr *tailPtr )
{
char value;
QueueNodePtr tempPtr;
value = (*headPtr )->data;
tempPtr= *headPtr;
*headPtr = ( headPtr )->nextPtr;
if ( *headPtr == NULL)
*tailPtr = NULL;
free ( tempPtr );
return value;
}
int isEmpty ( QueueNodePtr headPtr)
{
return headPtr == NULL;
}
void printQueue ( QueueNodePtr currentPtr )
{
if ( currentPtr == NULL )
printf("Queue is empty.\n\n"
while ( currentPtr != NULL )
{
printf( "%c --> ", currentPtr->data );
currentPtr = currentPtr->nextPtr;
}
printf("Null\n\n" );
}
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
struct queueNode
{ /*self-referential structure*/
char data;
struct queueNode *nextPtr;
};
typedef struct queueNode QueueNode;
typedef QueueNode *QueueNodePtr ;
/* function prototype*/
void printQueue ( QueueNodePtr );
int isEmpty( QueueNodePtr);
char dequeue( QueueNodePtr *, QueueNodePtr * );
void enqueue( QueueNodePtr *, QueueNodePtr *, char );
void instructions (void);
int main()
{
QueueNodePtr headPtr = NULL;
QueueNodePtr tailPtr = NULL;
int choice;
char item;
instructions ();
printf("?"
scanf("%d", &choice );
while ( choice !=3 )
{
switch( choice )
{
case 1:
printf( "Enter a character: "
scanf("\n%c", &item );
enqueue( &headPtr, &tailPtr, item );
printQueue ( headPtr );
break;
case 2:
if ( !isEmpty( headPtr ) )
{
item = dequeue( &headPtr, &tailPtr );
printf("%c has been dequeued.\n", item );
}
printQueue ( headPtr );
break;
default:
printf( "Bad Choice. \n\n" );
instructions();
break;
}
printf("?"
scanf("%d", &choice );
}
printf(" End of run.\n"
return 0;
}
void instructions (void)
{
printf("Enter your choice:\n"
" 1 to add an item to the queue\n"
" 2 to remove an item from the queue\n"
" 3 to end\" );
}
void enqueue ( QueueNodePtr *headPtr, QueueNodePtr *tailPtr,char value)
{
QueueNodePtr newPtr;
newPtr = malloc ( sizeof( QueueNode) );
if ( newPtr != NULL)
{
newPtr->data = value;
newPtr->nextPtr = NULL;
if ( isEmpty( *headPtr ) )
*headPtr = newPtr;
else
( *tailPtr )->nextPtr = newPtr;
*tailPtr = newPtr;
}
else
printf(" %c not inserted. No memory available.\n",value);
}
char dequeue ( QueueNodePtr *headerPtr, QueueNodePtr *tailPtr )
{
char value;
QueueNodePtr tempPtr;
value = (*headPtr )->data;
tempPtr= *headPtr;
*headPtr = ( headPtr )->nextPtr;
if ( *headPtr == NULL)
*tailPtr = NULL;
free ( tempPtr );
return value;
}
int isEmpty ( QueueNodePtr headPtr)
{
return headPtr == NULL;
}
void printQueue ( QueueNodePtr currentPtr )
{
if ( currentPtr == NULL )
printf("Queue is empty.\n\n"
while ( currentPtr != NULL )
{
printf( "%c --> ", currentPtr->data );
currentPtr = currentPtr->nextPtr;
}
printf("Null\n\n" );
}