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