0

i'm trying to write a doubly linked list code but i'm having a lot of errors please help me identify what my problem it please thank you in advance

#include <stdio.h>
#include <stdlib.h>

struct listNode
{ 
	char data;
    struct listNode *nextPtr; 
    //struct listNode *prevPtr; 
};
typedef struct listNode LISTNODE;
typedef LISTNODE *LISTNODEPTR;

void insert( LISTNODEPTR *, char );
char Delete( LISTNODEPTR *, char );
int isEmpty( LISTNODEPTR );
void printList( LISTNODEPTR );
void instructions(void);

int main(void)
{
	LISTNODEPTR startPtr = 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 );
			   insert( &startPtr, item );
			   printList( startPtr );
			   break;

		   case 2:

			   if (!isEmpty( startPtr ) )
			   {
				   printf( "Enter character to be deleted: " );
				   scanf( "\n%c", &item );

				   if ( Delete( &startPtr, item ) )
				   {
					   printf( "%c delete.\n", item );
					   printList( startPtr );
				   }
				   else
				   {
					   printf( "%c not found.\n\n", item );
				   }
			   }
			   else
			   {
				   printf( "List is empty.\n\n" );
			   }
			   break;

		   default:
			   printf( "Invalid choice.\n\n" );
			   instructions();
			   break;
		}//end switch

		printf( "? " );
		scanf( "%d", &choice );
	}//end while

	printf( "End of run.\n" );

	return 0;

}//end main

//prints instructions
void instructions(void)
{
	printf( "Enter your choice:\n"
		"  1 to insert an element into the list.\n"
		"  2 to delete an element from the list.\n"
		"  3 to end.\n" );
}//end function instrution

//insert new value
void insert( LISTNODEPTR *sPtr, char value )
{
	LISTNODEPTR newPtr, previousPtr, currentPtr;

	newPtr = malloc( sizeof( LISTNODE ) );

	if ( newPtr != NULL ) 
	{
		newPtr->data = value;
		newPtr->nextPtr = NULL;
		//newPtr->prevPtr = NULL;

		previousPtr = NULL;
		currentPtr = *sPtr;

		while ( currentPtr != NULL && value > currentPtr->data )
		{
			previousPtr = currentPtr;
			currentPtr = currentPtr->nextPtr;
			//currentPtr = currentPtr->*prevPtr;
		}//end while

		if ( previousPtr == NULL )
		{
			newPtr->nextPtr = *sPtr;
			//newPtr->*prevPtr = *sPtr;
			*sPtr = newPtr;
		}//end if
		else
		{
			previousPtr->nextPtr = newPtr;
			newPtr->nextPtr = currentPtr;
		}//end else

	}//end if
	else
	{
		printf( "%c not inserted. No memory available.\n", value );
	}//end else

}//end function insert

//delete list
int Delete( LISTNODEPTR *sPtr, int value )
{
	LISTNODEPTR previousPtr, currentPtr, tempPtr;

	if ( value == ( *sPtr )->data )
	{
		tempPtr = *sPtr;
		*sPtr = ( *sPtr )->nextPtr;
		//*sPtr = ( *sPtr )->*prevPtr;
		free( tempPtr );
		return value;
	}//end if
	else
	{
		previousPtr = *sPtr;
		currentPtr = ( *sPtr )->nextPtr;
		//currentPtr = ( *sPtr )->*prevPtr;

		while ( currentPtr != NULL && currentPtr->data != value )
		{
			previousPtr = currentPtr;
			currentPtr = currentPtr->nextPtr;
			//currentPtr = currentPtr->*prevPtr;
		}//end while

		if ( currentPtr != NULL )
		{
			tempPtr = currentPtr;
			previousPtr->nextPtr = currentPtr->nextPtr;
			//*previousPtr->*prevPtr = currentPtr->*prevPtr;
			free( tempPtr );
			return value;
		}//end if

	}//end else

	return '\0';

}//end function delete

int isEmpty( LISTNODEPTR sPtr )
{
	return sPtr == NULL;
}//end of function isEmpty

void printList( LISTNODEPTR currentPtr )
{
	if ( currentPtr == NULL )
	{
		printf( "List is empty.\n\n" );
	}//end if
	else
	{
		printf( "The list is:\n" );

		while ( currentPtr != NULL )
		{
			printf( "%c --> ", currentPtr->data );
			currentPtr = currentPtr->nextPtr;
		}//end while

		printf( "NULL\n\n" );
	}//end else
}//end funstion printList
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by firstPerson
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.