1. ## Double Linked List

This is my code for double linked list.
The pointer next is OK
I have big problem in creating the prev pointer.

Take a look:
Code:
```struct AkeraiosStruct {
int Value;

AkeraiosStruct * next;
AkeraiosStruct * prev;
} AkeraiosStruct;

//--------------------------------------------->

void insert_at_end (AkeraiosStruct * * ptraddr, int v)
/* Insert v as last element of list *ptraddr */

{
AkeraiosStruct * templist,prevnode;
templist = * ptraddr;

while (*ptraddr != NULL){                     /* Go to end of list */
ptraddr = &((*ptraddr)->next);                /* Prepare what we need to change */
}

*ptraddr = malloc(sizeof(struct AkeraiosStruct)); /* Space for new node */
(*ptraddr)->Value = v;                               /* Put value */
(*ptraddr)->next = NULL;              /* There is no next element */
}

void insert_at_start(AkeraiosStruct * *ptraddr, int v)
/* Insert v as first element of list *ptraddr */
{ AkeraiosStruct * templist,prevnode;

templist = *ptraddr;                /* Save current start of list */
*ptraddr = malloc(sizeof(struct AkeraiosStruct)); /* Space for new node */

(*ptraddr)->Value = v;                               /* Put value */
(*ptraddr)->next = templist;      /* Next element is former first */

}```
Can anyone tell me the exact problem?????

2. Code:
```struct AKERAIOSSTRUCT {
int Value;

AKERAIOSSTRUCT* next;
AKERAIOSSTRUCT* prev;
};

AKERAIOSSTRUCT AkeraiosStruct;```
will probably produce better results. its generally considered proper to use all caps when defining a struct type. plus your are using pointers all wrong.
Code:
`(*ptraddr)->Value = v;`
shoudl be
Code:
`ptraddr->Value = v;`
unless you are intending to pass the function a pointer to a pointer to a struct, in which case you should already understand pointers before trying a double redirect

3. its generally considered proper to use all caps when defining a struct type
never so it...
shoudl be
It shouldn't
unless you are intending to pass the function a pointer to a pointer
According to the function prototype - it is so.

Can anyone tell me the exact problem?????
YOU should the exact problem and we will try to show the path to solve it...

How you intend to use your function
What you want to achieve
What is the actual results...

some sample code with description what goes wrong will help

4. "prevnode" isn't declared as a pointer; It doesn't have a star in front of it. That would make a huge dent in your program's ability to perform the desired functions.

abachler: You are mostly alone in your usage of all capitals for struct definitions. Most people only use all capitals for macros.

5. I want to use these two functions in order to insert elements in each node of the struct.
In every node i will place only one number < 10.
Generaly i want to do operation for very huge numbers using lists.
e.x.

3541482438438443484

in the first node i will place number 3
in the second node i will place number 5
...
in the last node i will place number 4

So far using single linked list i achieved to do the operations of sum difference and i hope, using double linked list to achieve multiply and division digit to digit.
THe problem is i want to move forward and backward but i only can move forward.

6. Originally Posted by iMalc
abachler: You are mostly alone in your usage of all capitals for struct definitions. Most people only use all capitals for macros.
mostly, unless you also count everyone at microsoft, and 90&#37; of professional programmers.

7. Microsoft types everything in caps, so they don't count.

8. Originally Posted by MacGyver
Microsoft types everything in caps, so they don't count.
and linux people write obfuscated code, so lets not count them either, hmm, who do we have left, just me and you and a dog named boo, so I suppose it depends on the dog

9. Bah, who ever said Microsoft employees were people!

Microsoft even go as far as to define LONG long etc, just so that they can do their stupid over-uppercasing. Doesn't make them right, and doesn't mean most people will follow suit.

10. Originally Posted by abachler
and linux people write obfuscated code, so lets not count them either, hmm, who do we have left, just me and you and a dog named boo, so I suppose it depends on the dog
Obviously a Linux dog. If it was a Microsoft dog, it would be named BOO. if it's was a Mac dog, it would be named SomeIntelligentAndCoolMacDogThatIsNamedBoo.

11. Originally Posted by ch4
I want to use these two functions in order to insert elements in each node of the struct.
In every node i will place only one number < 10.
Generaly i want to do operation for very huge numbers using lists.
e.x.

3541482438438443484

in the first node i will place number 3
in the second node i will place number 5
...
in the last node i will place number 4

So far using single linked list i achieved to do the operations of sum difference and i hope, using double linked list to achieve multiply and division digit to digit.
THe problem is i want to move forward and backward but i only can move forward.
That is a horrendously inefficient way to implement a large number library. If you need a quick working solution I can point you towards a few existing solutions. However, I suggest you keep going with what you've got as you obviously still have much more to learn from doing this.

Popular pages Recent additions