Hi - i have been trying to create a linked list in C using structs and there are a couple of things i am stuck with how to declare the node front and back and do i keep repeating myself?
Also in the function push back how can i use the linked list i created ?

#include <stdlib.h>

typedef struct node
{
    int data;
    struct node* next;
    struct node* prev;
};

typedef struct llist
{
    struct node* front;
    struct node* back;
}llist;


llist* linked_list_create()
{
    llist* aLL = malloc(sizeof(llist));
    aLL->front = 0;
    aLL->back = 0;
    return aLL;
}

int linked_list_push_back(llist* aLL, int value)
{
   
 struct node tmp; 

tmp::value;
    int front= 0;
    struct node *newNode;
    newNode = (struct node *)malloc(sizeof(struct node));
    
    
    if(newNode != 0)
    {
        newNode->data = value; 
       
       newNode *next= front;
        newNode->prev = newNode ->next;
        return 1;
         
    }
    return 0;
}

int linked_list_pop_back(llist* aLL, int value)
{
   	
		    struct node * popped;
            popped = (struct node *)malloc(sizeof(struct node));
	    struct node* curr = front;
            struct node * curr;
            curr = (struct node *)malloc(sizeof(struct node);*/

if (popped != NULL)
		{
                        struct node* curr;
			popped = curr;
		        curr->next;	
			
			back->next = NULL;
 
			
			if (curr == front)
			{
				front = NULL; l
			}
 
			
           
            
		}
  
}
void main()
{
    llist* ll = linked_list_create();
    linked_list_push_back(11, 99);
    linked_list_pop_back(ll,9);

}

Thanks

Line 80

linked_list_push_back(11, 99);

Your passing the number eleven not your linked list pointer ll.

Line 80

linked_list_push_back(11, 99);

Your passing the number eleven not your linked list pointer ll.

thanks but on my complier the font makes them look the same.
its mainly the push back function i am worried about

Are you trying to create a double linked list that has a head node and a tail node with zero or more nodes linked in between? Because if that's your intent, you'll have get your 'linked_list_create' to create and link both of them(head and tail node) initially.

Are you trying to create a double linked list that has a head node and a tail node with zero or more nodes linked in between? Because if that's your intent, you'll have get your 'linked_list_create' to create and link both of them(head and tail node) initially.

yes - if you look at my code you will see that i do have them linked - the linked_list_create is fine i have had it checked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.