Guest_imported
New member
- Jan 1, 1970
- 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct listNode
{
char *Data;
struct listNode *nextPtr;
struct listNode *prevPtr;
};
typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;
void insert (ListNodePtr *, char *);
void printList (ListNodePtr );
int main()
{
ListNodePtr startPtr = NULL;
char item[512];
printf ("Enter the text line: \n"
fgets (item, sizeof(item), stdin );
insert (&startPtr, item);
printList (startPtr);
return 0;
}
void insert (ListNodePtr *listptr, char value[])
{
ListNodePtr newPtr, previousPtr, currentPtr;
newPtr = malloc (sizeof (ListNode) );
if ( newPtr != NULL)
{
newPtr->Data = value;
newPtr->nextPtr = NULL;
previousPtr = NULL;
currentPtr = *listptr;
while ( currentPtr != NULL && value != '.')
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
previousPtr = previousPtr->prevPtr;
}
if (previousPtr == NULL)
{
newPtr->nextPtr = *listptr;
*listptr = newPtr;
}
else
{
previousPtr->nextPtr = newPtr;
newPtr->nextPtr = currentPtr;
newPtr->prevPtr = previousPtr;
}
}
else
printf ("No memory is available."
}
void printList (ListNodePtr currentPtr)
{
printf ("The list is : \n"
printf ("%s\n", currentPtr->Data);
currentPtr = currentPtr->nextPtr;
while (currentPtr != NULL)
{
printf ("%s\n", currentPtr->Data);
currentPtr = currentPtr->nextPtr;
}
}
#include <stdlib.h>
#include <string.h>
struct listNode
{
char *Data;
struct listNode *nextPtr;
struct listNode *prevPtr;
};
typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;
void insert (ListNodePtr *, char *);
void printList (ListNodePtr );
int main()
{
ListNodePtr startPtr = NULL;
char item[512];
printf ("Enter the text line: \n"
fgets (item, sizeof(item), stdin );
insert (&startPtr, item);
printList (startPtr);
return 0;
}
void insert (ListNodePtr *listptr, char value[])
{
ListNodePtr newPtr, previousPtr, currentPtr;
newPtr = malloc (sizeof (ListNode) );
if ( newPtr != NULL)
{
newPtr->Data = value;
newPtr->nextPtr = NULL;
previousPtr = NULL;
currentPtr = *listptr;
while ( currentPtr != NULL && value != '.')
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
previousPtr = previousPtr->prevPtr;
}
if (previousPtr == NULL)
{
newPtr->nextPtr = *listptr;
*listptr = newPtr;
}
else
{
previousPtr->nextPtr = newPtr;
newPtr->nextPtr = currentPtr;
newPtr->prevPtr = previousPtr;
}
}
else
printf ("No memory is available."
}
void printList (ListNodePtr currentPtr)
{
printf ("The list is : \n"
printf ("%s\n", currentPtr->Data);
currentPtr = currentPtr->nextPtr;
while (currentPtr != NULL)
{
printf ("%s\n", currentPtr->Data);
currentPtr = currentPtr->nextPtr;
}
}