Thread: FIFO 2 LIFO
View Single Post
  #5 (permalink)  
Old May 2nd, 2004, 06:41 PM
mafuka mafuka is offline
Registered User
 
Join Date: Mar 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i think i did what you said here's my code

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct queueNode
{
   int data;
   struct queueNode *nextPtr;
};
typedef struct queueNode QueueNode;
typedef QueueNode *QueueNodePtr;
void printQueue( QueueNodePtr );
int isEmpty( QueueNodePtr );
int dequeue( QueueNodePtr *, QueueNodePtr * );
void enqueue( QueueNodePtr *, QueueNodePtr *, int );
void instructions( void );
int main()
{
   QueueNodePtr headPtr = NULL, tailPtr = NULL;
   int choice;
   int item;
   instructions();
   printf( "? " );
   scanf( "%d", &choice );
   while ( choice != 3 )
   {
      switch( choice )
      {
      case 1:
         printf( "Introduzca un Caracter: " );
         scanf( "\n%c", &item );
         enqueue( &headPtr, &tailPtr, item );
         printQueue( headPtr );
         break;
      case 2:
         if ( !isEmpty( headPtr ) )
         {
            item = dequeue( &headPtr, &tailPtr );
            printf( "%c a Sido Eliminado.\n", item );
         }
         printQueue( headPtr );
         break;
      default:
         printf( "Opcion Invalida.\n\n" );
         instructions();
         break;
      }
      printf( "? " );
      scanf( "%d", &choice );
   }
   printf( "Fin de Corrida.\n" );
   return 0;
}
void instructions( void )
{
   printf ( "Introduzca su Opcion:\n"
      " 1 Para Insertar un Elemento a la Cola\n"
      " 2 Para Eliminar un Elemento de la Cola\n"
      " 3 Para Salir\n" );
}
void enqueue( QueueNodePtr *headPtr, int value )
{
   QueueNodePtr newPtr;
   newPtr = new (QueueNode);
   if ( newPtr != NULL )
   {
      newPtr->data = value;
      newPtr->nextPtr = *headPtr;
      *headPtr = newPtr;
   }
   else
      printf( "%c No Insertado. No Memoria Disponible.\n", value );
}
int dequeue( QueueNodePtr *headPtr )
{
   QueueNodePtr tempPtr;
   int value;

   tempPtr = *headPtr;
   value = ( *headPtr )->data;
   *headPtr = ( *headPtr )->nextPtr;
   free( tempPtr );
   return value;
}

void printQueue( QueueNodePtr currentPtr )
{
   if ( currentPtr == NULL )
      printf( "La Cola esta Vacia.\n\n" );
   else
   {
      printf( "La Cola Es:\n" );
      while ( currentPtr != NULL )
      {
         printf( "%c --> ", currentPtr->data );
         currentPtr = currentPtr->nextPtr;
      }
      printf( "NULL\n\n" );
   }
}

when i compile it it doesn't mark any errors, but then when i try to run it i get these:
! ERROR: Unresolved external 'enqueue(queueNode**,queueNode**,int)' referenced from C:\MY DOCUMENTS\MY STACK.OBJ
! ERROR: Unresolved external 'isEmpty(queueNode*)' referenced from C:\MY DOCUMENTS\MY STACK.OBJ
! ERROR: Unresolved external 'dequeue(queueNode**,queueNode**)' referenced from C:\MY DOCUMENTS\MY STACK.OBJ

Reply With Quote