A linked list is a data structure where each node contains a data field and a pointer to the next node. A linked list can be singly linked, where each node only points to the next node, or doubly linked where each node points to both the next and previous nodes. A circular linked list is a variation where the last node points back to the first node, allowing it to be traversed indefinitely. Common operations on linked lists include insertion and deletion of nodes at different positions through manipulation of the node pointers.
A linked list is a collection of nodes that are randomly stored in memory and connected through pointers. Each node contains data and a pointer to the next node. The last node points to null. Linked lists allow for dynamic sizes, easy insertion/deletion, and non-contiguous storage in memory. Common operations include inserting nodes at the beginning, end, or a specified position and deleting nodes from the beginning, end, or a specified position.
This document discusses linked lists and representing stacks and queues using linked lists. It provides information on different types of linked lists including singly, doubly, and circular linked lists. It describes inserting, deleting, and traversing nodes in a singly linked list. It also provides a C program example to implement a stack using a linked list with functions for push, pop, and display operations. The document discusses how linked lists are dynamic data structures that can grow and shrink in size as needed, unlike arrays.
Linked lists are linear data structures where elements are linked using pointers. The three main types are singly, doubly, and circular linked lists. Linked lists allow dynamic memory allocation and fast insertion/deletion compared to arrays but slower access. A linked list contains nodes, each with a data field and pointer to the next node. Basic operations on linked lists include insertion, deletion, traversal, and search. Doubly linked lists include pointers to both the next and previous nodes.
This document discusses different types of linked lists including singly linked lists, circular linked lists, and doubly linked lists. It provides details on representing stacks and queues using linked lists. Key advantages of linked lists over arrays are that linked lists can dynamically grow in size as needed, elements can be inserted and deleted without shifting other elements, and there is no memory wastage. Operations like insertion, deletion, traversal, and searching are described for singly linked lists along with sample C code to implement a linked list, stack, and queue.
The document provides information on linked lists including:
- Linked lists are a linear data structure where each node contains data and a pointer to the next node.
- They allow for dynamic memory allocation and easier insertion/deletion than arrays.
- Common types include singly linked, doubly linked, circular singly/doubly linked lists.
- The document describes creating linked lists in C using structures, and operations like insertion, deletion, searching.
Heap memory is a common pool of dynamic memory used for allocating objects and data structures during program execution. It is part of RAM and allows for longer-lived allocations compared to stack memory. When the heap is full, garbage collection clears unused objects to free up space. Linked lists are linear data structures composed of nodes containing a data field and a pointer to the next node. They allow for dynamic sizes and efficient insertions/deletions unlike arrays. Doubly linked lists include pointers to both the next and previous nodes, allowing traversal in both directions but requiring more space.
The program implements operations on a stack using an array. It includes functions for push(), pop(), and display(). Push inserts an element into the stack if not full. Pop removes an element if not empty. Display prints the stack elements using a for loop. The main() uses a switch case to call the functions based on user input until exit is chosen.
The document discusses various primitive operations that can be performed on circular linked lists in C programming. It provides code implementations for inserting a node at the beginning and end of a circular linked list, inserting a node after a specified element, deleting the first and last elements, and deleting an element from a specified position. The time complexity of these operations is also discussed. Key operations include updating the next pointers of the preceding, current and next nodes to maintain the circular nature of the list during insertions and deletions.
Linked lists are linear data structures made up of nodes that contain data and a link to the next node. There are different types including singly linked lists where each node has one link, and doubly linked lists where each node has two links allowing traversal in both directions. Common operations on linked lists include inserting and deleting nodes, searching for a node, and displaying all nodes. Doubly linked lists make some operations like deleting a node more efficient since predecessors can be directly accessed through the backward link rather than traversing from the head.
Linked lists are data structures that store data in scattered locations in memory. Each data item or node contains a data part that holds the actual data and a link part that points to the next node. The nodes are linked together using these links. A linked list requires an external pointer to point to the first node. Operations like traversing, searching, inserting and deleting nodes can be performed on linked lists by manipulating these node links.
A linked list is a sequence of data structures, which are connected together via links.
Linked List is a sequence of links which contain items. Each link contains a connection to another link. Linked list is the second most-used data structure after the array.
A linked list is a linear data structure where each element (called a node) points to the next node in the list. Each node contains data and a pointer to the next node. The size of the linked list is not fixed as nodes can be added or removed anywhere in the list. There are different types of linked lists like singly linked lists and doubly linked lists. The code defines a struct node containing data and a pointer to the next node. It implements functions to create, display, insert, and delete nodes from the linked list.
This document provides information on various operations that can be performed on linked lists, including inserting, deleting, searching, sorting, and reversing nodes. It begins by explaining how to create a basic linked list with three nodes by allocating memory for each node, assigning data values, and connecting the nodes. It then discusses functions for inserting nodes at the beginning, middle, or end of the list. Other operations covered include traversing the list, deleting nodes, searching for a value, sorting nodes, and reversing the order of nodes. Code examples are provided for many of the operations.
This document discusses linked lists and their implementation in C. It begins by describing the differences between array-based and linked list implementations. Specifically, it notes that linked lists use dynamic memory allocation and pointers to connect nodes rather than contiguous memory blocks. The document then covers creating and traversing linked lists using nodes with data fields and next pointers. It provides code examples for inserting, finding, deleting and destroying nodes in a singly linked list. Finally, it briefly lists some other common linked list operations like sorting, reversing and finding min/max elements.
The document discusses linked lists and their implementation in C. It defines linked lists as dynamic data structures that store data in nodes linked together via pointers. The key operations on linked lists include insertion and deletion of nodes, as well as traversing and searching the list. It describes implementing linked lists as singly linked lists, doubly linked lists, and circular linked lists. Functions are provided for basic linked list operations like insertion, deletion, display on singly linked lists, and implementations of stacks and queues using linked lists.
Linked lists are dynamic data structures that can change size during program execution. Each element contains a data field and a pointer to the next element. Elements are linked together using these pointers. There are several types of linked lists including singly linked, doubly linked, circular linked lists. Basic operations on linked lists include traversing the list, inserting elements, and deleting elements. Linked lists are suitable when the number of elements is unknown or the list needs to be rearranged efficiently.
This document discusses singly linked lists and their insertion operations. It describes:
- A singly linked list consists of nodes where each node has a data field and pointer to the next node.
- There are three ways to insert a node: at the front by changing the head pointer, at the end by traversing to the last node, and at any position p by finding the predecessor node.
- Pseudocode is provided for functions to insert at the front, end, and at a given position p by updating the next pointers of the predecessor and new nodes.
- Data structures allow for efficient handling of large volumes of data through logical organization and relationships between data elements. Common linear data structures include arrays, lists, stacks, and queues, while trees and graphs are examples of non-linear data structures.
- Abstract data types (ADTs) define a set of complex data objects and operations that can be performed on those objects without specifying their implementation. Data structures provide a way to implement the logical relationships and operations defined in an ADT.
- Linked lists provide an alternative to arrays for storing data by linking each data element to the next using pointers, rather than requiring contiguous memory locations. This allows for more flexible insertion and deletion compared to arrays.
This document discusses linked lists and their operations. It begins with an introduction to linked lists and their types. It then covers the representation of linked lists, various operations on linked lists like insertion, deletion, traversal, and comparisons with arrays. It discusses different types of linked lists like single, double, circular single and circular double linked lists. It provides algorithms for common linked list operations like insertion and deletion on single and double linked lists.
This document provides information on linked lists. Some key points:
- A linked list is a dynamic data structure where elements are linked using pointers. Each element contains a data field and a pointer to the next node.
- There are different types of linked lists including singly linked, doubly linked, circular, and circular doubly linked lists.
- Common linked list operations include insertion, deletion, traversal, searching, and sorting. Algorithms for performing these operations on singly linked lists are presented.
- Linked lists can be used to implement other data structures like stacks, where the top element is tracked using a pointer instead of using array indices. Pseudocode for push and pop operations on a linked list implementation of
This document discusses different types of linked lists including singly linked lists, doubly linked lists, circular linked lists, and their implementations. It provides code examples for creating, traversing, inserting, deleting nodes from singly linked lists as well as implementing a stack using linked lists. The key advantages and disadvantages of linked lists over arrays are also summarized.
This document discusses representations of sparse matrices using linked lists. It explains that sparse matrices, which contain mostly zero values, can be stored more efficiently using a triplet representation or linked representation rather than a standard 2D array. The triplet representation stores only the non-zero elements, their row and column indices, and matrix size information. It provides an example of a 4x5 sparse matrix represented as a triplet array with 6 non-zero elements. Linked representation stores the sparse matrix as a linked list, where each node contains the row, column and value of a non-zero element. Applications of sparse matrix representations include storing large sparse datasets efficiently.
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...Karim Baïna
Artificial Intelligence (AI) is reshaping societies and raising complex ethical, legal, and geopolitical questions. This talk explores the foundations and limits of Trustworthy AI through the lens of global frameworks such as the EU’s HLEG guidelines, UNESCO’s human rights-based approach, OECD recommendations, and NIST’s taxonomy of AI security risks.
We analyze key principles like fairness, transparency, privacy, robustness, and accountability — not only as ideals, but in terms of their practical implementation and tensions. Special attention is given to real-world contexts such as Morocco’s deployment of 4,000 intelligent cameras and the country’s positioning in AI readiness indexes. These examples raise critical issues about surveillance, accountability, and ethical governance in the Global South.
Rather than relying on standardized terms or ethical "checklists", this presentation advocates for a grounded, interdisciplinary, and context-aware approach to responsible AI — one that balances innovation with human rights, and technological ambition with social responsibility.
This rich Trustworthy and Responsible AI frameworks context is a serious opportunity for Human and Social Sciences Researchers : either operate as gatekeepers, reinforcing existing ethical constraints, or become revolutionaries, pioneering new paradigms that redefine how AI interacts with society, knowledge production, and policymaking ?
More Related Content
Similar to TutorialII_Updated____niceupdateprogram.pdf (20)
Heap memory is a common pool of dynamic memory used for allocating objects and data structures during program execution. It is part of RAM and allows for longer-lived allocations compared to stack memory. When the heap is full, garbage collection clears unused objects to free up space. Linked lists are linear data structures composed of nodes containing a data field and a pointer to the next node. They allow for dynamic sizes and efficient insertions/deletions unlike arrays. Doubly linked lists include pointers to both the next and previous nodes, allowing traversal in both directions but requiring more space.
The program implements operations on a stack using an array. It includes functions for push(), pop(), and display(). Push inserts an element into the stack if not full. Pop removes an element if not empty. Display prints the stack elements using a for loop. The main() uses a switch case to call the functions based on user input until exit is chosen.
The document discusses various primitive operations that can be performed on circular linked lists in C programming. It provides code implementations for inserting a node at the beginning and end of a circular linked list, inserting a node after a specified element, deleting the first and last elements, and deleting an element from a specified position. The time complexity of these operations is also discussed. Key operations include updating the next pointers of the preceding, current and next nodes to maintain the circular nature of the list during insertions and deletions.
Linked lists are linear data structures made up of nodes that contain data and a link to the next node. There are different types including singly linked lists where each node has one link, and doubly linked lists where each node has two links allowing traversal in both directions. Common operations on linked lists include inserting and deleting nodes, searching for a node, and displaying all nodes. Doubly linked lists make some operations like deleting a node more efficient since predecessors can be directly accessed through the backward link rather than traversing from the head.
Linked lists are data structures that store data in scattered locations in memory. Each data item or node contains a data part that holds the actual data and a link part that points to the next node. The nodes are linked together using these links. A linked list requires an external pointer to point to the first node. Operations like traversing, searching, inserting and deleting nodes can be performed on linked lists by manipulating these node links.
A linked list is a sequence of data structures, which are connected together via links.
Linked List is a sequence of links which contain items. Each link contains a connection to another link. Linked list is the second most-used data structure after the array.
A linked list is a linear data structure where each element (called a node) points to the next node in the list. Each node contains data and a pointer to the next node. The size of the linked list is not fixed as nodes can be added or removed anywhere in the list. There are different types of linked lists like singly linked lists and doubly linked lists. The code defines a struct node containing data and a pointer to the next node. It implements functions to create, display, insert, and delete nodes from the linked list.
This document provides information on various operations that can be performed on linked lists, including inserting, deleting, searching, sorting, and reversing nodes. It begins by explaining how to create a basic linked list with three nodes by allocating memory for each node, assigning data values, and connecting the nodes. It then discusses functions for inserting nodes at the beginning, middle, or end of the list. Other operations covered include traversing the list, deleting nodes, searching for a value, sorting nodes, and reversing the order of nodes. Code examples are provided for many of the operations.
This document discusses linked lists and their implementation in C. It begins by describing the differences between array-based and linked list implementations. Specifically, it notes that linked lists use dynamic memory allocation and pointers to connect nodes rather than contiguous memory blocks. The document then covers creating and traversing linked lists using nodes with data fields and next pointers. It provides code examples for inserting, finding, deleting and destroying nodes in a singly linked list. Finally, it briefly lists some other common linked list operations like sorting, reversing and finding min/max elements.
The document discusses linked lists and their implementation in C. It defines linked lists as dynamic data structures that store data in nodes linked together via pointers. The key operations on linked lists include insertion and deletion of nodes, as well as traversing and searching the list. It describes implementing linked lists as singly linked lists, doubly linked lists, and circular linked lists. Functions are provided for basic linked list operations like insertion, deletion, display on singly linked lists, and implementations of stacks and queues using linked lists.
Linked lists are dynamic data structures that can change size during program execution. Each element contains a data field and a pointer to the next element. Elements are linked together using these pointers. There are several types of linked lists including singly linked, doubly linked, circular linked lists. Basic operations on linked lists include traversing the list, inserting elements, and deleting elements. Linked lists are suitable when the number of elements is unknown or the list needs to be rearranged efficiently.
This document discusses singly linked lists and their insertion operations. It describes:
- A singly linked list consists of nodes where each node has a data field and pointer to the next node.
- There are three ways to insert a node: at the front by changing the head pointer, at the end by traversing to the last node, and at any position p by finding the predecessor node.
- Pseudocode is provided for functions to insert at the front, end, and at a given position p by updating the next pointers of the predecessor and new nodes.
- Data structures allow for efficient handling of large volumes of data through logical organization and relationships between data elements. Common linear data structures include arrays, lists, stacks, and queues, while trees and graphs are examples of non-linear data structures.
- Abstract data types (ADTs) define a set of complex data objects and operations that can be performed on those objects without specifying their implementation. Data structures provide a way to implement the logical relationships and operations defined in an ADT.
- Linked lists provide an alternative to arrays for storing data by linking each data element to the next using pointers, rather than requiring contiguous memory locations. This allows for more flexible insertion and deletion compared to arrays.
This document discusses linked lists and their operations. It begins with an introduction to linked lists and their types. It then covers the representation of linked lists, various operations on linked lists like insertion, deletion, traversal, and comparisons with arrays. It discusses different types of linked lists like single, double, circular single and circular double linked lists. It provides algorithms for common linked list operations like insertion and deletion on single and double linked lists.
This document provides information on linked lists. Some key points:
- A linked list is a dynamic data structure where elements are linked using pointers. Each element contains a data field and a pointer to the next node.
- There are different types of linked lists including singly linked, doubly linked, circular, and circular doubly linked lists.
- Common linked list operations include insertion, deletion, traversal, searching, and sorting. Algorithms for performing these operations on singly linked lists are presented.
- Linked lists can be used to implement other data structures like stacks, where the top element is tracked using a pointer instead of using array indices. Pseudocode for push and pop operations on a linked list implementation of
This document discusses different types of linked lists including singly linked lists, doubly linked lists, circular linked lists, and their implementations. It provides code examples for creating, traversing, inserting, deleting nodes from singly linked lists as well as implementing a stack using linked lists. The key advantages and disadvantages of linked lists over arrays are also summarized.
This document discusses representations of sparse matrices using linked lists. It explains that sparse matrices, which contain mostly zero values, can be stored more efficiently using a triplet representation or linked representation rather than a standard 2D array. The triplet representation stores only the non-zero elements, their row and column indices, and matrix size information. It provides an example of a 4x5 sparse matrix represented as a triplet array with 6 non-zero elements. Linked representation stores the sparse matrix as a linked list, where each node contains the row, column and value of a non-zero element. Applications of sparse matrix representations include storing large sparse datasets efficiently.
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...Karim Baïna
Artificial Intelligence (AI) is reshaping societies and raising complex ethical, legal, and geopolitical questions. This talk explores the foundations and limits of Trustworthy AI through the lens of global frameworks such as the EU’s HLEG guidelines, UNESCO’s human rights-based approach, OECD recommendations, and NIST’s taxonomy of AI security risks.
We analyze key principles like fairness, transparency, privacy, robustness, and accountability — not only as ideals, but in terms of their practical implementation and tensions. Special attention is given to real-world contexts such as Morocco’s deployment of 4,000 intelligent cameras and the country’s positioning in AI readiness indexes. These examples raise critical issues about surveillance, accountability, and ethical governance in the Global South.
Rather than relying on standardized terms or ethical "checklists", this presentation advocates for a grounded, interdisciplinary, and context-aware approach to responsible AI — one that balances innovation with human rights, and technological ambition with social responsibility.
This rich Trustworthy and Responsible AI frameworks context is a serious opportunity for Human and Social Sciences Researchers : either operate as gatekeepers, reinforcing existing ethical constraints, or become revolutionaries, pioneering new paradigms that redefine how AI interacts with society, knowledge production, and policymaking ?
An Algorithmic Test Using The Game of PokerGraham Ware
In an interview you may be presented with a poker set and asked to create a game that mimics the market and data science. Here is a fun way we created such a scenario.
apidays New York 2025 - Agentic AI Future by Seena Ganesh (Staples)apidays
Agentic AI Future: Agents Reshaping Digital Transformation and API Strategy
Seena Ganesh, Vice President Engineering - B2C & B2B eCommerce & Digital AI at Staples
apidays New York 2025
API Management for Surfing the Next Innovation Waves: GenAI and Open Banking
Convene 360 Madison, New York
May 14 & 15, 2025
------
Check out our conferences at https://www.apidays.global/
Do you want to sponsor or talk at one of our conferences?
https://apidays.typeform.com/to/ILJeAaV8
Learn more on APIscene, the global media made by the community for the community:
https://www.apiscene.io
Explore the API ecosystem with the API Landscape:
https://apilandscape.apiscene.io/
Embracing AI in Project Management: Final Insights & Future VisionKavehMomeni1
🚀 Unlock the Future of Project Management: Embracing AI – Final Session!
This presentation is the culminating session (Session 13) of the "AI Applications in Project Management Workshop," hosted by OnAcademy and instructed by Kaveh Momeni, PMP®, COB & AI Lead at Chaharsotoon.
Dive deep into "Embracing AI: Empowering Project Managers for an AI-Driven Future." We consolidate critical learnings from the entire workshop and provide a forward-looking perspective on how AI is revolutionizing project management.
Inside, you'll discover:
A Comprehensive Course Recap: Key takeaways from across the workshop, covering everything from knowledge management and predictive analytics to AI agents.
Cutting-Edge AI Trends: The latest developments in AI impacting PM, including market growth, task automation, and the rise of autonomous project assistants.
AI vs. Human Capabilities: Understanding the unique strengths of AI and the irreplaceable value of human intuition, strategic thinking, and leadership in PM.
Optimizing Human-AI Collaboration: Practical models and frameworks for seamlessly integrating AI tools into PM workflows, emphasizing prompt engineering and growth mindsets.
Cultivating AI-Ready Mindsets: Strategies to foster organizational cultures that embrace AI as an opportunity for innovation and competitive advantage.
Essential Skills for Future-Proof PMs: Identifying the core competencies, including AI literacy, data-driven decision-making, and ethical AI governance, crucial for thriving in an AI-augmented world.
Implementation Roadmap & Best Practices: A strategic guide for integrating AI into your projects and organizations, from pilot projects to establishing Centers of Excellence.
Ethical & Practical Considerations: Navigating data quality, bias, transparency, regulatory compliance (like the EU AI Act), and human-centric values in AI-driven PM.
A Vision for AI-Enabled PM: Envisioning AI as a strategic partner, leading to enhanced outcomes, sustainable competitive advantage, and the rise of the "AI-Augmented PM."
Actionable Next Steps: Concrete steps you can take today to advance your AI journey in project management.
Presented by Kaveh Momeni, a seasoned Project Manager with 15+ years of experience and extensive AI/ML certifications from leading institutions. This session is designed to empower project managers, team leaders, and decision-makers to confidently navigate and leverage AI for transformative project success.
Perfect for anyone looking to understand the strategic implications of AI in project delivery and how to prepare for an AI-driven future.
The final presentation of our time series forecasting project in the "Data Science for Society and Business" Master's program at Constructor University Bremen
apidays New York 2025 - AI for All by Ananya Upadhyay (United Rentals, Inc.)apidays
AI for All: Industry Use Cases & Early Career Impact in GenAI
Ananya Upadhyay, AI Developer at United Rentals, Inc.
apidays New York 2025
API Management for Surfing the Next Innovation Waves: GenAI and Open Banking
Convene 360 Madison, New York
May 14 & 15, 2025
------
Check out our conferences at https://www.apidays.global/
Do you want to sponsor or talk at one of our conferences?
https://apidays.typeform.com/to/ILJeAaV8
Learn more on APIscene, the global media made by the community for the community:
https://www.apiscene.io
Explore the API ecosystem with the API Landscape:
https://apilandscape.apiscene.io/
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxsofiawilliams5966
Autonomous vehicles represent the cutting edge of modern technology, promising to revolutionize transportation by improving safety, efficiency, and accessibility.
The final presentation of our time series forecasting project for the "Data Science for Society and Business" Master's program at Constructor University Bremen
2. Problem 2: Write a program in C to insert a node in the
middle of a Singly Linked List.
Test Data and Expected Output :
Input the number of nodes (3 or more) : 4
Input data for node 1 : 10
Input data for node 2 : 20
Input data for node 3 : 30
Input data for node 4 : 40
Data entered in the list are :
Data = 10
Data = 20
Data = 30
Data = 40
Input data to insert in the list : 25
Input the position to insert new node : 3
Insertion completed successfully.
Updated Linked List:
Data entered in the list are :
Data = 10
Data = 20
Data = 25
Data = 30
Data = 40
Problem 1: Write a program in C to create
and display a Singly Linked List.
Test Data :
Input the number of nodes : 4
Input data for node 1 : 10
Input data for node 2 : 20
Input data for node 3 : 30
Input data for node 4 : 40
Expected Output :
Data entered in the list are:
Data = 10
Data = 20
Data = 30
Data = 40
3. Problem 3: Write a C program that converts a singly
linked list into an array and returns it.
Test Data and Expected Output :
Linked List: Convert a Singly Linked list into a string
-------------------------------------------------------------
Input the number of nodes: 3
Input data for node 1 : 10
Input data for node 2 : 20
Input data for node 3 : 30
Return data entered in the list as a string:
The linked list: 10 20 30
Problem 4: Write a C program to merge two sorted
singly linked lists into a single sorted linked list.
Test Data and Expected Output :
Two sorted singly linked lists:
1 7 19 29
3 13 23
After merging the said two sorted lists:
1 3 7 13 19 23 29
Problem 5: Write a Count() function that counts the
number of times a given int occurs in a list.
Problem 6: Write a GetNth() function that takes a
linked list and an integer index and returns the data
value stored in the node at that index position.
Problem 7: Write a function DeleteList() that takes a
list, deallocates all of its memory and sets its head
pointer to NULL (the empty list).
4. Problem 8: Suppose 5 employee works in Capgemini. Each employee is having details
as Name, Employee Id, CTC in LPA, Experience in years. Create a linked list that stores
details for 5 employees. Use C code.
Problem 9: Suppose 3 employee works in Google. Each employee is accompanied with
details as Name, Employee Id, CTC in LPA, Experience in years. Suppose, each employee
gets new password each day at the time they are reporting to the company (1st Day of
Joining). The password is to be assigned for today and a new password is to be displayed
for each employee for next day (login credentials for next day). The password needs to be
of 8 digits. Create a linked list that stores all these details for the employees. Use C code.
Problem 10: Given a 2-D matrix. Convert it into a linked list matrix such that each node is
linked to its next right and down node and display it. Use C Code.
*The idea is to create a new node for each element of the matrix and then create its next
down and right nodes in a recursive manner.
5. #include <stdio.h>
#include <stdlib.h>
typedef struct stud {
int Data;
struct stud* next;} node;
node *create_list() // Function to create a linked list
{
int k, n, count = 1;
node *p, *head;
printf ("n Input the number of nodes :");
scanf ("%d", &n);
for (k=0; k<n; k++) // Create the list
{
if (k == 0) {
head = (node *) malloc(sizeof(node));
p = head;
}
else {
p->next = (node *) malloc(sizeof(node));
p = p->next;
}
printf("n Input data for node %d:", count);
scanf ("%d", &p->Data);
count++;
}
p->next = NULL; // Set the last node's next to NULL
return (head);
}
void display (node *head) // Function to traverse and display a
linked list
{
node *p;
p = head;
while (p != NULL)
{
printf ("nData = %d ",
p->Data);
p = p->next;
}
printf ("n");
}
int main() {
node *head = NULL; // Declare head pointer
head = create_list(); // Create the list and assign it to head
display(head); // Display the list
return 0; // Return success
}
Problem 1: Singly Linked Link List
6. #include <stdio.h>
#include <stdlib.h>
typedef struct stud {
int Data;
struct stud* next;
struct stud* prev; // Pointer to the previous node
} node;
node* create_list() // Function to create a doubly linked list
{
int k, n, count = 1;
node *p, *head = NULL, *prev_node = NULL;
printf("n Input the number of nodes: ");
scanf("%d", &n);
for (k = 0; k < n; k++) // Create the list
{
if (k == 0) {
head = (node*) malloc(sizeof(node)); // Create the first node
p = head;
p->prev = NULL; // First node has no previous node
}
else {
p->next = (node*) malloc(sizeof(node)); // Allocate new node
prev_node = p; // Store the current node as previous before moving
p = p->next; // Move to the newly created node
p->prev = prev_node; // Link back to the previous node
}
printf("n Input data for node %d: ", count);
scanf("%d", &p->Data);
p->next = NULL; // Set next pointer to NULL initially
count++;
}
return head;
}
void display(node* head) // Function to traverse and display a doubly linked list
{
node *p = head;
printf("nForward traversal:n");
while (p != NULL) {
printf("Data = %dn", p->Data);
p = p->next;
}
}
void display_reverse(node* head) // Function to traverse in reverse
{
node *p = head;
// Traverse to the last node
while (p->next != NULL) {
p = p->next;
}
printf("nReverse traversal:n");
while (p != NULL) {
printf("Data = %dn", p->Data);
p = p->prev;
}
}
int main() {
node *head = NULL; // Declare head pointer
head = create_list(); // Create the doubly linked list
display(head); // Display the list in forward direction
display_reverse(head); // Display the list in reverse direction
return 0; // Return success
}
Problem 1: Doubly Linked Link List
7. Problem 1: Circular Linked Link List
#include <stdio.h>
#include <stdlib.h>
typedef struct stud {
int Data;
struct stud* next;
} node;
node *create_list() // Function to create a circular linked list
{
int k, n, count = 1;
node *p, *head, *tail = NULL; // Adding tail to connect last node to head
printf ("n Input the number of nodes: ");
scanf ("%d", &n);
for (k = 0; k < n; k++) // Create the list
{
if (k == 0) {
head = (node *) malloc(sizeof(node));
p = head;
}
else {
p->next = (node *) malloc(sizeof(node));
p = p->next;
}
printf("n Input data for node %d: ", count);
scanf("%d", &p->Data);
count++;
if (k == n - 1) {
tail = p; // Mark the last node
}
}
p->next = head; // Set the last node's next to head to make it circular
return head;
}
void display(node *head) // Function to traverse and display a
circular linked list
{
node *p = head;
if (head == NULL) {
printf("The list is empty.n");
return;
}
do {
printf("nData = %d", p->Data);
p = p->next;
} while (p != head); // Stop when we reach the head again
printf("n");
}
int main() {
node *head = NULL; // Declare head pointer
head = create_list(); // Create the list and assign it to head
display(head); // Display the list
return 0; // Return success
}
8. #include <stdio.h>
#include <stdlib.h>
typedef struct stud {
int Data;
struct stud* next;
} node;
node* create_list() // Function to create a linked list
{
int k, n, count = 1;
node *p, *head;
printf("nInput the number of nodes (3 or more) : ");
scanf("%d", &n);
for (k = 0; k < n; k++) // Create the list
{
if (k == 0) {
head = (node *) malloc(sizeof(node));
p = head;
}
else {
p->next = (node *) malloc(sizeof(node));
p = p->next;
}
printf("nInput data for node %d: ", count);
scanf("%d", &p->Data);
count++;
}
p->next = NULL; // Set the last node's next to NULL
return (head);
}
void display(node *head) // Function to traverse and display a linked list
{
printf("nData entered in the list are: ");
node *p = head;
while (p != NULL)
{
printf("nData = %d", p->Data);
p = p->next;
}
printf("n");
}
void insert_at_position(node **head_ref, int data, int position) {
node *new_node = (node *)malloc(sizeof(node));
new_node->Data = data;
// If inserting at the head (position 1)
if (position == 1) {
new_node->next = *head_ref;
*head_ref = new_node;
return;
}
node *temp = *head_ref;
for (int i = 1; temp != NULL && i < position - 1; i++) {
temp = temp->next;
}
// If position is greater than the number of nodes
if (temp == NULL) {
printf("nPosition is out of boundsn");
free(new_node);
return;
}
// Insert the node
new_node->next = temp->next;
temp->next = new_node;
printf("nInsertion completed successfully.");
}
int main() {
node *head = NULL; // Declare head pointer
int position, data;
head = create_list(); // Create the list and assign it to head
display(head); // Display the list
// Insert a new node at a specific position
printf("nInput data to insert in the list : ");
scanf("%d", &data);
printf("Input the position to insert new node : ");
scanf("%d", &position);
insert_at_position(&head, data, position);
printf("nUpdated Linked List:");
display(head); // Display the updated list
return 0;
}
Problem 2
9. #include <stdio.h>
#include <stdlib.h>
// Node structure for the linked list
struct Node {
int data;
struct Node* next;
};
// Function to create a new node
struct Node* createNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
return newNode;
}
// Function to convert the linked list to an array
void linkedListToArray(struct Node* head, int* arr, int n) {
struct Node* temp = head;
for (int i = 0; i < n && temp != NULL; i++) {
arr[i] = temp->data;
temp = temp->next;
}
}
// Function to display the array
void displayArray(int* arr, int n) {
printf("The linked list: ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("n");
}
int main() {
struct Node* head = NULL;
struct Node* temp = NULL;
int n, data;
printf("Input the number of nodes: ");
scanf("%d", &n);
// Creating the linked list
for (int i = 1; i <= n; i++) {
printf("Input data for node %d: ", i);
scanf("%d", &data);
struct Node* newNode = createNode(data);
if (head == NULL) {
head = newNode;
} else {
temp->next = newNode;
}
temp = newNode;
}
// Create an array to hold the linked list elements
int arr[n];
// Convert the linked list to an array
linkedListToArray(head, arr, n);
// Display the array
printf("nReturn data entered in the list as a string:n");
displayArray(arr, n);
return 0;
}
Problem 3
11. Problem 5:
int Count(struct node* head, int searchFor) {
struct node* current = head;
int count = 0;
while (current != NULL) {
if (current->data == searchFor) count++;
current = current->next;
}
return count;
}
Problem 6:
int GetNth(struct node* head, int index) {
struct node* current = head;
int count = 0; // the index of the node we're currently looking at
while (current != NULL) {
if (count == index) return(current->data);
count++;
current = current->next;
}
assert(0); // if we get to this line, the caller was asking
// for a non-existent element so we assert fail.
}
Problem 7:
void DeleteList(struct node** headRef) {
struct node* current = *headRef; // deref headRef to get the real head
struct node* next;
while (current != NULL) {
next = current->next; // note the next pointer
free(current); // delete the node
current = next; // advance to the next node
}
*headRef = NULL; // Again, deref headRef to affect the real head back
// in the caller.
}
12. #include <stdio.h>
#include <stdlib.h>
// Define the structure for an employee
struct Employee {
char name[100];
int employeeId;
float CTC;
int experience;
struct Employee* next;
};
// Function to create a new employee node
struct Employee* createEmployee() {
struct Employee* newEmployee = (struct
Employee*)malloc(sizeof(struct Employee));
printf("Enter Name: ");
scanf(" %[^n]", newEmployee->name);
printf("Enter Employee ID: ");
scanf("%d", &newEmployee->employeeId);
printf("Enter CTC (in LPA): ");
scanf("%f", &newEmployee->CTC);
printf("Enter Experience (in years): ");
scanf("%d", &newEmployee->experience);
newEmployee->next = NULL; // Set the next pointer to NULL
return newEmployee;
}
// Function to add an employee to the list
void appendEmployee(struct Employee** head) {
struct Employee* newEmployee = createEmployee();
if (*head == NULL) {
*head = newEmployee; // If the list is empty, make this the head
} else {
struct Employee* temp = *head;
while (temp->next != NULL) { // Traverse to the end of the list
temp = temp->next;
}
temp->next = newEmployee; // Add the new employee at the end
}
}
// Function to display employee details
void displayEmployees(struct Employee* head) {
if (head == NULL) {
printf("No employees in the list.n");
return;
}
struct Employee* temp = head;
while (temp != NULL) {
printf("nName: %sn", temp->name);
printf("Employee ID: %dn", temp->employeeId);
printf("CTC: %.2f LPAn", temp->CTC);
printf("Experience: %d yearsn", temp->experience);
temp = temp->next; // Move to the next employee
}
}
Problem 8
13. int main() {
struct Employee* head = NULL;
int numEmployees = 20;
// Input and append 20 employees to the list
for (int i = 0; i < numEmployees; i++) {
printf("nEnter details for Employee %d:n", i + 1);
appendEmployee(&head);
}
// Display all employee details
printf("nEmployee Details:n");
displayEmployees(head);
return 0;
}
14. #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define PASSWORD_LENGTH 8
// Define the structure for an employee
struct Employee {
char name[100];
int employeeId;
float CTC;
int experience;
char password[PASSWORD_LENGTH + 1]; // Field for storing the password
struct Employee* next;
};
// Function to create a random password
void generatePassword(char* password) {
const char charset[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (int i = 0; i < PASSWORD_LENGTH; i++) {
int randomIndex = rand() % (sizeof(charset) - 1);
password[i] = charset[randomIndex];
}
password[PASSWORD_LENGTH] = '0'; // Null-terminate the password
}
Problem 9
15. // Function to create a new employee node
struct Employee* createEmployee() {
struct Employee* newEmployee = (struct Employee*)malloc(sizeof(struct Employee));
printf("Enter Name: ");
scanf(" %[^n]", newEmployee->name);
printf("Enter Employee ID: ");
scanf("%d", &newEmployee->employeeId);
printf("Enter CTC: ");
scanf("%f", &newEmployee->CTC);
printf("Enter Experience (in years): ");
scanf("%d", &newEmployee->experience);
// Generate and assign a password to the employee
generatePassword(newEmployee->password);
newEmployee->next = NULL; // Set the next pointer to NULL
return newEmployee;
}
// Function to assign a new password each day
void assignDailyPassword(struct Employee* employee) {
generatePassword(employee->password); // Generate a new password
}
16. // Function to add an employee to the list
void appendEmployee(struct Employee** head) {
struct Employee* newEmployee = createEmployee();
if (*head == NULL) {
*head = newEmployee; // If the list is empty, make this the head
} else {
struct Employee* temp = *head;
while (temp->next != NULL) { // Traverse to the end of the list
temp = temp->next;
}
temp->next = newEmployee; // Add the new employee at the end
}
}
// Function to display employee details along with the current password
void displayEmployees(struct Employee* head) {
if (head == NULL) {
printf("No employees in the list.n");
return;
}
struct Employee* temp = head;
while (temp != NULL) {
printf("nName: %sn", temp->name);
printf("Employee ID: %dn", temp->employeeId);
printf("CTC: %.2fn", temp->CTC);
printf("Experience: %d yearsn", temp->experience);
printf("Password: %sn", temp->password); // Display the current password
temp = temp->next; // Move to the next employee
}
}
17. // Function to simulate daily reporting and password generation
void dailyReport(struct Employee* head) {
struct Employee* temp = head;
while (temp != NULL) {
assignDailyPassword(temp); // Assign a new password for the day
temp = temp->next;
}
}
int main() {
srand(time(0)); // Initialize random number generator for password
generation
struct Employee* head = NULL;
int numEmployees = 1; // Change this to 20 in real use
// Input and append employees to the list
for (int i = 0; i < numEmployees; i++) {
printf("nEnter details for Employee %d:n", i + 1);
appendEmployee(&head);
}
// Simulate the first day's reporting
printf("nEmployee Details (First Day):n");
displayEmployees(head);
// Simulate the second day where new passwords are assigned
printf("nAssigning new passwords for the next day...n");
dailyReport(head);
// Display employee details after new passwords are assigned
printf("nEmployee Details (Next Day):n");
displayEmployees(head);
return 0;
}
18. #include <stdio.h>
#include <stdlib.h>
// Define the structure for a node
struct Node {
int data;
struct Node *right;
struct Node *down;
};
// Function to create a new node
struct Node* createNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->right = NULL;
newNode->down = NULL;
return newNode;
}
// Function to convert a 2D matrix into a linked list matrix
struct Node* convertToLinkedListMatrix(int rows, int cols, int matrix[rows][cols]) {
struct Node* head[rows][cols]; // Array of pointers to store the nodes
// Create all nodes
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
head[i][j] = createNode(matrix[i][j]);
}
}
Problem 10
19. // Link nodes together: Right and Down
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (j < cols - 1)
head[i][j]->right = head[i][j + 1]; // Link to the right
if (i < rows - 1)
head[i][j]->down = head[i + 1][j]; // Link downward
}
}
// Return the head of the matrix (top-left corner)
return head[0][0];
}
// Function to display the linked list matrix
void displayLinkedListMatrix(struct Node* head) {
struct Node* rowPtr = head;
while (rowPtr != NULL) {
struct Node* colPtr = rowPtr;
while (colPtr != NULL) {
printf("%d ", colPtr->data);
colPtr = colPtr->right; // Move to the next node in the row
}
printf("n");
rowPtr = rowPtr->down; // Move to the next row
}
}
int main() {
int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Convert the 2D matrix to a linked list matrix
struct Node* head = convertToLinkedListMatrix(3, 3, matrix);
// Display the linked list matrix
displayLinkedListMatrix(head);
return 0;
}