Question: c programming!!!!!! A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply

c programming!!!!!!

A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. have only studied the doubly-linked, circular, with a dummy-header-node version of a linked list.

The addFirst function will insert a new data item into the list at position 0 (in front of all the items already in the list).

The removeLast function deletes the last item in the list (at position size-1), and returns the data that was deleted from the List. If removeLast is invoked on an empty List, then it should output an error message, leave the list unchanged, and return the NULL pointer.

The effect of the clear function is to make the List become an empty List. The set function should alter the value of the data at the specified location in the list. The size of the list remains the same. The set function should return the item that was deleted from the List (because it was overwritten by the new item). If the set function references an illegal index, then it should print an error message, and the list should be unchanged. You should implement each of these functions in the most efficient manner possible. Your function should not take O(n) time when an O(1) solution is possible. Also, the set function should be as efficient as possible. If the target location (e.g., index) is more than halfway down the linked list, then the traversal should start from the rear of the list and move leftwards.

#include

#include

#include

typedef struct node { // represents one node in a Linked List

void *data; // pointer to data associated with this node

struct node *next; // pointer to next node in List

struct node *prev; // pointer to previous node in List

} Node;

typedef struct { // represents a Linked List

Node *header; // pointer to the "dummy header node" of

// the Linked List

int size; // number of nodes in the Linked List

} LinkedList;

// function proto-types

void createList ( LinkedList *someList );

void addEnd( LinkedList *someList, void *newElement );

void *delete( LinkedList *someList, int position );

void outputList( LinkedList *someList );

void addFirst( LinkedList *someList, void *newElement );

void *removeLast( LinkedList *someList );

void clear( LinkedList *someList );

void *set( LinkedList *someList, int position, void *newElement );

#define MAX_NAME_LENGTH 20

int main() {

LinkedList myList;

LinkedList *roster = &myList;

createList ( roster ); // initialize the fields of the list

// process a sequence of List operations from stdin

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!