Linked List – Strings – Problem #2

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

Problem Statement

In this program, we will implement some elementary functions of linked list. Define your linked list as follows. typedef struct node{ int data; struct node* next; } node; typedef node *linkedlist; Part I: Write a function to initialize a linked list Write a function to initialize a linked list. The prototype should be as follows which initializes the linked list pointed by l. void init(linkedlist* l); Part II: Write a function to display a linked list Write a function to display a linked list. The prototype should be as follows which displays the linked list l. void display(linkedlist l); Part III: Write a function to insert at the front of a linked list Write a function to insert an elements at the front of a linked list. The prototype should be as follows which inserts an integer x at the front of the linked list pointed by l. void insert_front(linkedlist* l, int x); Part IV: Write a function to delete an element from the front of a linked list Write a function to delete an element from the front of a linked list. The prototype should be as follows which deletes an element from the linked list pointed by l. The function should not do anything if the linked list pointed by l is empty. void delete_front(linkedlist* l); Part V: Write a function to reverse a linked list Write a function to a linked list. The prototype should be as follows which reverses the linked list pointed by l. The function should not do anything if the linked list pointed by l is empty. void reverse(linkedlist* l); All the functions from parts III to V also displays the modified linked list. Make sure, you free any space which you do not need anymore. Submit one (single) C/C++ program. Sample Output insert_front 10: (10) insert_front 100: (100,10) reverse: (10,100) delete_front: (100) delete_front: ()

Back to Lab Problems
Linked List/Strings/Problem #2

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #2

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.