How do you save a custom linked list (double linked list?) on to a file?
By : SuneelM
Date : March 29 2020, 07:55 AM
I hope this helps you . If you have to use text files, then what I would suggest is to find some sort of scheme to correspond lines to attributes and from that scheme, rebuild the linked list as you read them for file. As the scheme, look at this small example. Imagine you only wanted to save a list of Monetary. What you could do was, for each item on the list, you would save, in each line: The value of the variable 'value' The length of the array of strings (let's say n strings) n strings
|
Comparing the running of a linked list and a custom linked list
By : Akash Srivastava
Date : March 29 2020, 07:55 AM
should help you out Since the custom list always adds words to the front, the dictionary will be in the reverse order of how the terms were read in. For the normal dictionary that won't make much of a difference, but when you use the text of Romeo and Juliet itself as the dictionary, this is what you'll end up with: Romeo and Juliet: "Two households, both alike in dignity ... Than this of Juliet and her Romeo."
|
Swift 3 and Index of a custom linked list collection type
By : Vighneshwar Mishra
Date : March 29 2020, 07:55 AM
Hope that helps Here's my take on it. a) I introduced one private integer type property to my custom Index type: depth.
|
custom linked list creating RtlValidateHeap error with the structures having a Linked list
By : Satya Das
Date : March 29 2020, 07:55 AM
Hope that helps You have a rule of three (or four or five) violation. You've defined a custom destructor, but not a custom assignment operator. In your case, this ends up causing two separate LinkedList objects to point to the same nodes. More info: https://stackoverflow.com/a/4782927/951890
|
How can I return the odd indexed nodes of a singly linked list in a new singly linked list ?Assume index of the first no
By : user3675293
Date : March 29 2020, 07:55 AM
it fixes the issue When I run this code I am not getting an error message from the compiler but I can not return the new list. Am I writing down the code wrong in the MAIN part? , You are always changing the same object pList->next. code :
else
{
pList->next=pTemp;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct SinglyLinkedListItem
{
int data;
struct SinglyLinkedListItem *next;
} SLLI;
SLLI * OddNodes( SLLI **pHead )
{
int odd = 0;
SLLI *pList = NULL;
SLLI **pCurrent = &pList;
while ( *pHead != NULL )
{
if ( odd ^= 1 )
{
*pCurrent = *pHead;
*pHead = ( *pHead )->next;
( *pCurrent )->next = NULL;
pCurrent = &( *pCurrent )->next;
}
else
{
pHead = &( *pHead )->next;
}
}
return pList;
}
int insert( SLLI **pHead, int data )
{
SLLI *pCurrent = malloc( sizeof( SLLI ) );
int success = pCurrent != NULL;
if ( success )
{
pCurrent->data = data;
pCurrent->next = *pHead;
*pHead = pCurrent;
}
return success;
}
void out( SLLI *pHead )
{
for ( ; pHead != NULL; pHead = pHead->next )
{
printf( "%d -> ", pHead->data );
}
puts( "null" );
}
int main(void)
{
const int N = 10;
SLLI *pHead = NULL;
for ( int i = N; i != 0; --i )
{
insert( &pHead, 10 * i );
}
out( pHead );
SLLI *pSecondHead = OddNodes( &pHead );
out( pHead );
out( pSecondHead );
return 0;
}
10 -> 20 -> 30 -> 40 -> 50 -> 60 -> 70 -> 80 -> 90 -> 100 -> null
20 -> 40 -> 60 -> 80 -> 100 -> null
10 -> 30 -> 50 -> 70 -> 90 -> null
#include <stdio.h>
#include <stdlib.h>
typedef struct SinglyLinkedListItem
{
int data;
struct SinglyLinkedListItem *next;
} SLLI;
SLLI * OddNodes( SLLI *pHead )
{
int odd = 0;
SLLI *pList = NULL;
SLLI **pCurrent = &pList;
for ( ; pHead != NULL; pHead = pHead->next )
{
if ( odd ^= 1 )
{
*pCurrent = malloc( sizeof( SLLI ) );
( *pCurrent )->data = pHead->data;
( *pCurrent )->next = NULL;
pCurrent = &( *pCurrent )->next;
}
}
return pList;
}
int insert( SLLI **pHead, int data )
{
SLLI *pCurrent = malloc( sizeof( SLLI ) );
int success = pCurrent != NULL;
if ( success )
{
pCurrent->data = data;
pCurrent->next = *pHead;
*pHead = pCurrent;
}
return success;
}
void out( SLLI *pHead )
{
for ( ; pHead != NULL; pHead = pHead->next )
{
printf( "%d -> ", pHead->data );
}
puts( "null" );
}
int main(void)
{
const int N = 10;
SLLI *pHead = NULL;
for ( int i = N; i != 0; --i )
{
insert( &pHead, 10 * i );
}
out( pHead );
SLLI *pSecondHead = OddNodes( pHead );
out( pHead );
out( pSecondHead );
return 0;
}
10 -> 20 -> 30 -> 40 -> 50 -> 60 -> 70 -> 80 -> 90 -> 100 -> null
10 -> 20 -> 30 -> 40 -> 50 -> 60 -> 70 -> 80 -> 90 -> 100 -> null
10 -> 30 -> 50 -> 70 -> 90 -> null
SLLI * OddNodes( SLLI *pHead )
{
int odd = 0;
SLLI *pList = NULL;
for ( SLLI *pCurrent = pList; pHead != NULL; pHead = pHead->next )
{
if ( odd ^= 1 )
{
if ( pCurrent == NULL )
{
pList = malloc( sizeof( SLLI ) );
pList->data = pHead->data;
pList->next = NULL;
pCurrent = pList;
}
else
{
pCurrent->next = malloc( sizeof( SLLI ) );
pCurrent->next->data = pHead->data;
pCurrent->next->next = NULL;
pCurrent = pCurrent->next;
}
}
}
return pList;
}
|