# Thread: Function to add node between first and last node

1. ## Function to add node between first and last node

How to make function that can add the new node between fist and last node

for example

20 40
add new value 30

list 20 30 40

add new value 50

list 20 30 50 40

Code:
```#include <stdio.h>

#include <stdlib.h>

struct Node
{
int Data;
struct Node * Next;
};

struct Node * Add_New ( int n, struct Node * Pointer)
{

struct Node *New = malloc(sizeof(*New));

// return Pointer;
}

int main ()
{

struct Node * Head = NULL;
struct Node * Tail = NULL;
struct Node * Tail = malloc(sizeof(*Tail));

return 0;
}```

2. You've already been shown how to add to the head and tail of a list.
You therefore ought to be able to at least make an ATTEMPT for yourself now.

3. Originally Posted by Salem
You've already been shown how to add to the head and tail of a list.
You therefore ought to be able to at least make an ATTEMPT for yourself now.
My ATTEMPT to solve problem

I have already shown my code. I have only problem with code

4. OK, so you understand pictorially what you need to do.

How about some code to go with it?

5. Originally Posted by Salem
OK, so you understand pictorially what you need to do.

How about some code to go with it?
I have tried to write code, see post 1 But having trouble making full code So I asked how to make a function for list

6. Before you write code, write down detailed step-by-step instructions in English (or whatever language you're most comfortable with) on how you would accomplish the task. Think of it like a recipe: 1. do this, 2. do that, etc. Make sure each step is a simple task that even a simple-minded person can follow (a computer is a simple-minded, but very fast, person). This is often the "hard" part.

Once you do that, then convert the instructions, line by line, into code. This is the "easy" part.

Popular pages Recent additions