- 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 presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the visualization of the code w.r.t pointers.
Linked List Static and Dynamic Memory AllocationProf Ansari
Static variables are declared and named while writing the program. (Space for them exists as long as the program, in which they are declared, is running.) Static variables cannot be created or destroyed during execution of the program in which they are declared.
Dynamic variables are created (and may be destroyed) during program execution since dynamic variables do not exist while the program is compiled, but only when it is run, they cannot be assigned names while it is being written. The only way to access dynamic variables is by using pointers. Once it is created, however, a dynamic variable does contain data and must have a type like any other variable. If a dynamic variable is created in a function, then it can continue to exist even after the function terminates.
Linked Linear List
We saw in previous chapters how static representation of linear ordered list through Array leads to wastage of memory and in some cases overflows. Now we don't want to assign memory to any linear list in advance instead we want to allocate memory to elements as they are inserted in list. This requires Dynamic Allocation of memory and it can be achieved by using malloc() or calloc() function.
But memory assigned to elements will not be contiguous, which is a requirement for linear ordered list, and was provided by array representation. How we could achieve this?
Doubly Linked List || Operations || AlgorithmsShubham Sharma
Doubly linked list and operations on it. Insertion, Deletion, Traversing at all locations- First, Last, Middle.
Basic definitions and structured example.
Algorithms for all the operations.
linked list
singly linked list
insertion in singly linked list
DELETION IN SINGLY LINKED LIST
Searching a singly linked list
Doubly Linked List
insertion from Doubly linked list
DELETION from Doubly LINKED LIST
Searching a doubly linked list
Circular linked list
In computer science, a linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next
This course teaches engineering students how to program in C. I gave this course for several years in the framework of the "Advanced Technology Higher Education Network" / SOCRATES program.
This presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the visualization of the code w.r.t pointers.
Linked List Static and Dynamic Memory AllocationProf Ansari
Static variables are declared and named while writing the program. (Space for them exists as long as the program, in which they are declared, is running.) Static variables cannot be created or destroyed during execution of the program in which they are declared.
Dynamic variables are created (and may be destroyed) during program execution since dynamic variables do not exist while the program is compiled, but only when it is run, they cannot be assigned names while it is being written. The only way to access dynamic variables is by using pointers. Once it is created, however, a dynamic variable does contain data and must have a type like any other variable. If a dynamic variable is created in a function, then it can continue to exist even after the function terminates.
Linked Linear List
We saw in previous chapters how static representation of linear ordered list through Array leads to wastage of memory and in some cases overflows. Now we don't want to assign memory to any linear list in advance instead we want to allocate memory to elements as they are inserted in list. This requires Dynamic Allocation of memory and it can be achieved by using malloc() or calloc() function.
But memory assigned to elements will not be contiguous, which is a requirement for linear ordered list, and was provided by array representation. How we could achieve this?
Doubly Linked List || Operations || AlgorithmsShubham Sharma
Doubly linked list and operations on it. Insertion, Deletion, Traversing at all locations- First, Last, Middle.
Basic definitions and structured example.
Algorithms for all the operations.
linked list
singly linked list
insertion in singly linked list
DELETION IN SINGLY LINKED LIST
Searching a singly linked list
Doubly Linked List
insertion from Doubly linked list
DELETION from Doubly LINKED LIST
Searching a doubly linked list
Circular linked list
In computer science, a linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next
This course teaches engineering students how to program in C. I gave this course for several years in the framework of the "Advanced Technology Higher Education Network" / SOCRATES program.
this presentation is made for the students who finds data structures a complex subject
this will help students to grab the various topics of data structures with simple presentation techniques
best regards
BCA group
(pooja,shaifali,richa,trishla,rani,pallavi,shivani)
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
Data Structures in C++
I am really new to C++, so links are really hard topic for me. It would be nice if you can provide
explanations of what doubly linked lists are and of some of you steps... Thank you
In this assignment, you will implement a doubly-linked list class, together with some list
operations. To make things easier, you’ll implement a list of int, rather than a template class.
Solution
A variable helps us to identify the data. For ex: int a = 5; Here 5 is identified through variable a.
Now, if we have collection of integers, we need some representation to identify them. We call it
array. For ex: int arr[5]
This array is nothing but a Data Structure.
So, a Data Structure is a way to group the data.
There are many Data Structures available like Arrays, Linked List, Doubly-Linked list, Stack,
Queue, etc.
Doubly-Linked list are the ones where you can traverse from the current node both in left and
right directions.
Why so many different types of Data Structures are required ?
Answer is very simple, grouping of data, storage of data and accessing the data is different.
For example, in case of Arrays we store all the data in contiguous locations.
What if we are not able to store the data in contiguous locations because we have huge data.
Answer is go for Linked List/Doubly-Linked list.
Here we can store the data anywhere and link the data through pointers.
I will try to provide comments for the code you have given. May be this can help you.
#pragma once
/*
dlist.h
Doubly-linked lists of ints
*/
#include
class dlist {
public:
dlist() { }
// Here we are creating a NODE, it has a integer value and two pointers.
// One pointer is to move to next node and other to go back to previous node.
struct node {
int value;
node* next;
node* prev;
};
// To return head pointer, i.e. start of the Doubly-Linked list.
node* head() const { return _head; }
// To return Tail pointer, i.e. end of the Doubly-Linked list.
node* tail() const { return _tail; }
// **** Implement ALL the following methods ****
// Returns the node at a particular index (0 is the head).
node* at(int index){
int cnt = 0;
struct node* tmp = head();
while(tmp!=NULL)
{
if (cnt+1 == index)
return tmp;
tmp = tmp->next;
}
}
// Insert a new value, after an existing one
void insert(node *previous, int value){
// check if the given previous is NULL
if (previous == NULL)
{
printf(\"the given previous node cannot be NULL\");
return;
}
// allocate new node
struct node* new_node =(struct node*) malloc(sizeof(struct node));
// put in the data
new_node->data = new_data;
// Make next of new node as next of previous
new_node->next = previous->next;
// Make the next of previous as new_node
previous->next = new_node;
// Make previous as previous of new_node
new_node->prev = previous;
// Change previous of new_node\'s next node
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
// Delete the given node
void del(node* which){
struct node* head_ref = head();
/* base case */
if(*head_ref == NUL.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
ccvcvbcbvcbvcbvcbvcb vngfg hgjhg gj jgjhgjhgjhg jhgh jhgjhgj gjhgjhgjhgjhgjhgjhgjhg jghgjhgjhgjhgjhg jjghjhgjhgjhgjhgjh hgjhgjhgjhgjhgjhgjhgjgjhgjhgjhg hgfgfhdfhtftfj jgyjyyyugyugyug yjgghgjhgjhf drdfhgfgfgfgj jgjhgjhgjhgjhgjhg jhgghjfgf fxdx gfd hdhfd tftyf yytfy ytftyf ytf ytfty fytftykgh kghjg jhghgh fgfghfgh fgfghfgf gfgfgfgfytf hgfggf ghfgfg gjhghjg cfffgh jgfgfhgffhg hghh yuy ygyyuyutyutyu jgfghfhgfghfh fghfhgfhgf fthfhfhf hfhfhgf hfhgfghf fghfghfghfhhgfghf jgjhgjhgjhgjhgjhgj jgjhgjh jgjhg jgjhgjhgjhg jhgjhgjhg jhgjhg jhgjhgollowing the announcement of Google+ API deprecation scheduled for March 2019, a number of changes will be made to Blogger’s Google+ integration on 4 February 2019. *Google+ widgets:* Support for the “+1 Button”, “Google+ Followers” and “Google+ Badge” widgets in Layout will no longer be available. All instances of these widgets will be removed from all blogs. *+1 buttons:* The +1/G+ buttons and Google+ share links below blog posts and in the navigation bar will be removed. Please note that if you have a custom template that includes Google+ features, you may need to update ... read more ollowing the announcement of Google+ API deprecation scheduled for March 2019, a number of changes will be made to Blogger’s Google+ integration on 4 February 2019. *Google+ widgets:* Support for the “+1 Button”, “Google+ Followers” and “Google+ Badge” widgets in Layout will no longer be available. All instances of these widgets will be removed from all blogs. *+1 buttons:* The +1/G+ buttons and Google+ share links below blog posts and in the navigation bar will be removed. Please note that if you have a custom template that includes Google+ features, you may need to update ... read moreollowing the announcement of Google+ API deprecation scheduled for March 2019, a number of changes will be made to Blogger’s Google+ integration on 4 February 2019. *Google+ widgets:* Support for the “+1 Button”, “Google+ Followers” and “Google+ Badge” widgets in Layout will no longer be available. All instances of these widgets will be removed from all blogs. *+1 buttons:* The +1/G+ buttons and Google+ share links below blog posts and in the navigation bar will be removed. Please note that if you have a custom template that includes Google+ features, you may need to update ... read moreollowing the announcement of Google+ API deprecation scheduled for March 2019, a number of changes will be made to Blogger’s Google+ integration on 4 February 2019. *Google+ widgets:* Support for the “+1 Button”, “Google+ Followers” and “Google+ Badge” widgets in Layout will no longer be available. All instances of these widgets will be removed from all blogs. *+1 buttons:* The +1/G+ buttons and Google+ share links below blog posts and in the navigation bar will be removed. Please note that if you have a custom template that includes Google+ features, you may need to update ... read moreollowing the announcement of Google+ API deprecation scheduled for March 2019, a nu
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Unit7 C
1. Data Structures -- Data processing often involves in processing huge volumes of data. Many Companies handle million records of data stored in database. Many ways are formulated to handle data efficiently. -- An User-defined data type is a combination of different primary data types, which represents a complex entity. -- An Abstract Data Type ( A D T ) not only represents a set of complex data objects, but also includes a set of operations to be performed on these objects, defines that how the data objects are organized. -- The group of methods implements a set rules, which defines a logical way of handling data. -- The complex entity along with its group of methods is called Abstract Data Type ( A D T ) . -- Data structure is described as an instance of Abstract Data Type ( ADT ). -- We can define that Data structure is a kind of representation of logical relationship between related data elements. In data structure, decision on the operations such as storage, retrieval and access must be carried out between the logically related data elements. Data Structure Linear Non-Linear Stacks Queues Trees Graphs Linear Lists Some Data structures Arrays Strings Lists Stacks Queues Trees Graphs Dictionaries Maps Hash Tables Sets Lattice Neural-Nets Some Common Operations on Data structures Insertion : adding a new element to the collection. Deletion : removing an element from a collection. Traversal : access and examine each element in collection. Search : find whether an element is present or not. Sorting : rearranging elements in a particular order. Merging : combining two collections into one collection.
2.
3. struct node { int rollno; struct node *next; }; int main() { struct node *head,*n1,*n2,*n3,*n4; /* creating a new node */ n1=(struct node *) malloc(sizeof(struct node)); n1->rollno=101; n1->next = NULL; /* referencing the first node to head pointer */ head = n1; /* creating a new node */ n2=(struct node *)malloc(sizeof(struct node)); n2->rollno=102; n2->next = NULL; /* linking the second node after first node */ n1->next = n2; /* creating a new node * / n3=(struct node *)malloc(sizeof(struct node)); n3->rollno=104; n3->next=NULL; /* linking the third node after second node */ n2->next = n3; /* creating a new node */ n4=(struct node *)malloc (sizeof (struct node)); n4->rollno=103; n4->next=NULL; /* inserting the new node between second node and third node */ n2->next = n4; n4->next = n3; /* deleting n2 node */ n1->next = n4; free(n2); } Creating a Singly Linked List 150 head 150 400 720 910 n1-node n2-node n4-node n3-node 150 n1-node 150 head 150 150 n1-node n2-node 720 150 150 n1-node n2-node 720 910 n3-node 150 head 150 400 720 910 n1-node n2-node n4-node n3-node 101 400 102 720 103 910 104 NULL 101 NULL 101 720 102 NULL 101 720 102 910 104 NULL 101 720 102 720 103 910 104 NULL
4. struct node { int data; struct node *next; }; struct node *createnode() { struct node *new; new = (struct node *)malloc(sizeof(struct node)); printf("Enter the data : "); scanf("%d",&new->data); new->next = NULL; return new; } void append(struct node **h) { struct node *new,*temp; new = createnode(); if(*h == NULL) { *h = new; return; } temp = *h; while(temp->next!=NULL) temp = temp->next; temp->next = new; } void display(struct node *p) { printf("Contents of the List : "); while(p!=NULL) { printf("%d",p->data); p = p->next; } } void insert_after(struct node **h) { struct node *new,*temp; int k; if(*h == NULL) return; printf("Enter data of node after which node : "); scanf("%d",&k); temp = *h; while(temp!=NULL && temp->data!=k) temp = temp->next; if(temp!=NULL) { new=createnode(); new->next = temp->next; temp->next = new; } } void insert_before(struct node **h) { struct node *new,*temp,*prev ; int k; if(*h==NULL) return; printf("Enter data of node before which node : "); scanf("%d",&k); if((*h)->data == k) { new = createnode(); new->next = *h; *h = new; return; } temp = (*h)->next; prev = *h; Implementing Singly Linked List
5. while(temp!=NULL && temp->data!=k) { prev=temp; temp=temp->next; } if(temp!=NULL) { new = createnode(); new->next = temp; prev->next = new; } } void delnode(struct node **h) { struct node *temp,*prev; int k; if(*h==NULL) return; printf("Enter the data of node to be removed : "); scanf("%d",&k); if((*h)->data==k) { temp=*h; *h=(*h)->next; free(temp); return; } temp=(*h)->next; prev=*h; while(temp!=NULL && temp->data!=k) { prev=temp; temp=temp->next; } if(temp!=NULL) { prev->next = temp->next; free(temp); } } void search(struct node *h) { struct node *temp; int k; if(h==NULL)return; printf("Enter the data to be searched : "); scanf("%d",&k); temp=h; while(temp!=NULL && temp->data!=k) temp=temp->next; (temp==NULL)? printf("=>Node does not exist") : printf("=>Node exists"); } void destroy(struct node **h) { struct node *p; if(*h==NULL) return; while(*h!=NULL) { p = (*h)->next; free(*h); *h=p; } printf(" ******Linked List is destroyed******"); } Implementing Singly Linked List ( continued )
6. int main() { struct node *head=NULL; int ch; while(1) { printf("1.Append"); printf("2.Display All"); printf("3.Insert after a specified node"); printf("4.Insert before a specified node"); printf("5.Delete a node"); printf("6.Search for a node"); printf("7.Distroy the list"); printf("8.Exit program"); printf("Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1:append(&head);break; case 2:display(head);break; case 3:insert_after(&head);break; case 4:insert_before(&head);break; case 5:delnode(&head);break; case 6:search(head);break; case 7:destroy(&head);break; case 8:exit(0);break; default : printf( "Wrong Choice, Enter correct one : "); } } } /* function to sort linked list */ void sort(struct node *h) { struct node *p,*temp; int i, j, n, t, sorted=0; temp=h; for(n=0 ; temp!=NULL ; temp=temp->next) n++; for(i=0;i<n-1&&!sorted;i++) { p=h; sorted=1; for(j=0;j<n-(i+1);j++) { if ( p->data > ( p->next )->data ) { t=p->data; p->data =(p->next)->data; (p->next)->data = t; sorted=0; } p=p->next; } } } /* function to count number of node in the list */ int count ( struct node *h) { int i; for( i=0 ; h!=NULL ; h=h->next) i++; return i; } Implementing Singly Linked List ( continued )
7. Add_Polynomial( list p, list q ) set p, q to point to the two first nodes (no headers) initialize a linked list r for a zero polynomial while p != null and q != null if p.exp > q.exp create a node storing p.coeff and p.exp insert at the end of list r advance p else if q.exp > p.exp create a node storing q.coeff and q.exp insert at the end of list r advance q else if p.exp == q.exp if p.coeff + q.coeff != 0 create a node storing p.coeff + q.coeff and p.exp insert at the end of list r advance p, q end while if p != null copy the remaining terms of p to end of r else if q != null copy the remaining terms of q to end of r Algorithm for adding two polynomials in linked lists
8.
9. A B C D A B D C q p q A B C D p A B C Insertion of node in Doubly Linked List Deletion of node in Doubly Linked List
11. void insert_before(struct node **h) { struct node *new,*temp; int k; if(*h==NULL) return; printf("Enter data of node before which node : "); scanf("%d",&k); if((*h)->data == k) { new = createnode(); new->next = *h; new->next->prev=new; *h = new; return; } temp = *h; while(temp!=NULL && temp->data!=k) { temp=temp->next; } if(temp!=NULL) { new = createnode(); new->next = temp; new->prev = temp->prev; new->prev->next = new; temp->prev = new; } } void delnode(struct node **h) { struct node *temp; int k; if(*h==NULL) return; printf("Enter the data of node to be removed : "); scanf("%d",&k); if((*h)->data==k) { temp=*h; *h=(*h)->next; (*h)->prev=NULL; free(temp); return; } temp=*h; while(temp!=NULL && temp->data!=k) { temp=temp->next; } if(temp!=NULL) { temp->next->prev = temp->prev; temp->prev->next = temp->next; free(temp); } } Implementing Doubly Linked List ( continued )
12. void search(struct node *h) { struct node *temp; int k; if(h==NULL) return; printf("Enter the data to be searched : "); scanf("%d",&k); temp=h; while(temp!=NULL && temp->data!=k) temp=temp->next; if (temp==NULL) printf("=>Node does not exist") else printf("=>Node exists"); } void destroy(struct node **h) { struct node *p; if(*h==NULL) return; while(*h!=NULL) { p = (*h)->next; free(*h); *h=p; } printf(" ******Linked List is destroyed******"); } int main() { struct node *head=NULL; int ch; while(1) { printf("1.Append"); printf("2.Display All"); printf("3.Insert after a specified node"); printf("4.Insert before a specified node"); printf("5.Delete a node"); printf("6.Search for a node"); printf("7.Distroy the list"); printf("8.Exit program"); printf("Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1:append(&head);break; case 2:forward_display(head);break; case 3:insert_after(&head);break; case 4:insert_before(&head);break; case 5:delnode(&head);break; case 6:search(head);break; case 7:destroy(&head);break; case 8:exit(0);break; default : printf("Wrong Choice, Enter correct choice : "); } } } Implementing Doubly Linked List ( continued )
13. Circular Singly Linked List 910 tail 150 400 720 910 n1-node n2-node n3-node n4-node -- Singly Linked List has a major drawback. From a specified node, it is not possible to reach any of the preceding nodes in the list. To overcome the drawback, a small change is made to the SLL so that the next field of the last node is pointing to the first node rather than NULL. Such a linked list is called a circular linked list. -- Because it is a circular linked list, it is possible to reach any node in the list from a particular node. -- There is no natural first node or last node because by virtue of the list is circular. -- Therefore, one convention is to let the external pointer of the circular linked list, tail, point to the last node and to allow the following node to be the first node. -- If the tail pointer refers to NULL, means the circular linked list is empty. Circular Doubly Linked List -- A Circular Doubly Linked List ( CDL ) is a doubly linked list with first node linked to last node and vice-versa. -- The ‘ prev ’ link of first node contains the address of last node and ‘ next ’ link of last node contains the address of first node. -- Traversal through Circular Singly Linked List is possible only in one direction. -- The main advantage of Circular Doubly Linked List ( CDL ) is that, a node can be inserted into list without searching the complete list for finding the address of previous node. -- We can also traversed through CDL in both directions, from first node to last node and vice-versa. 101 400 102 720 103 910 104 150 prev data next prev data next prev data next prev data next
14. void insert_after(struct node **t) { struct node *new,*temp; int k, found=0; if(*t == NULL) return; printf("Enter data of node after which node : "); scanf("%d",&k); if((*t)->data==k) { new = createnode(); new->next = (*t)->next; (*t)->next = new; *t=new; return; } temp=(*t)->next; while(temp!=*t) { if(temp->data == k) { new = createnode(); new->next = temp->next; temp->next = new; found=1; break; } temp=temp->next; } if(found==0) printf("Node does not exist.."); } Implementing Circular Singly Linked List struct node { int data; struct node *next; }; struct node *createnode() { struct node *new; new = (struct node *)malloc(sizeof(struct node)); printf("Enter the data : "); scanf("%d",&new->data); new->next = NULL; return new; } void append(struct node **t) { struct node *new,*head; new = createnode(); if(*t == NULL) { *t = new; new->next = *t; return; } head = (*t)->next; (*t)->next = new; new->next = head; *t = new; } void display(struct node *t) { struct node *temp = t->next, *head=t->next; printf("Contents of the List : "); do { printf("%d",temp->data);temp = temp->next; }while(temp!=head); printf(“”); }
15. void insert_before(struct node **t) { struct node *new,*temp,*prev,*head; int k,found=0; if(*t==NULL) return; printf("Enter data of node before which node : "); scanf("%d",&k); head=(*t)->next; if(head->data == k) { new = createnode(); new->next = head; (*t)->next = new; return; } temp = head->next; prev = head; while(temp!=head) { if(temp->data==k) { new = createnode(); prev->next = new; new->next = temp; found=1; break; } else { prev=temp; temp=temp->next; } } if(found==0) printf("Node does not exist.."); } void delnode(struct node **t) { struct node *temp,*prev,*head; int k,found=0; if(*t==NULL) return; printf("Enter the data of node to be removed : "); scanf("%d",&k); head=(*t)->next; if(head->data==k) { temp=head; if(temp->next!=head) (*t)->next=head->next; else *t = NULL; free(temp); return; } temp=head->next; prev=head; while(temp!=head) { if(temp->data == k) { prev->next = temp->next; if(temp==*t) *t = prev; free(temp); found=1; break; } else { prev=temp; temp=temp->next; } } if(found==0) printf("Node does not exist.."); } Implementing Circular Singly Linked List ( continued )
16. int main() { struct node *tail=NULL; int ch; while(1) { printf("1.Append"); printf("2.Display All"); printf("3.Insert after a specified node"); printf("4.Insert before a specified node"); printf("5.Delete a node"); printf("6.Exit program"); printf("Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1:append(&tail);break; case 2:display(tail);break; case 3:insert_after(&tail);break; case 4:insert_before(&tail);break; case 5:delnode(&tail);break; case 6:exit(0);break; default : printf(“Wrong Choice… “); } } } Implementing Circular Singly Linked List ( continued ) Data structures are classified in several ways : Linear : Elements are arranged in sequential fashion. Ex : Array, Linear list, stack, queue Non-Linear : Elements are not arranged in sequence. Ex : trees, graphs Homogenous : All Elements are belongs to same data type. Ex : Arrays Non-Homogenous : Different types of Elements are grouped and form a data structure. Ex: classes Dynamic : Memory allocation of each element in the data structure is done before their usage using D.M.A functions Ex : Linked Lists Static : All elements of a data structure are created at the beginning of the program. They cannot be resized. Ex : Arrays Types of Data Structures
17.
18.
19. #define SIZE 50 int stack[SIZE]; int top; void init_stack() { top=-1; } void push( int n ) { if( top==SIZE-1) printf("Stack is full"); else stack[++top]= n; } int pop( ) { if(top== -1) { printf("Stack is empty"); return -1; } else return stack[top--]; } void display( ) { int i; if(top== -1) printf("Stack is empty."); else { printf("Elements are : "); for(i=0;i<=top;i++) printf("%5d ",stack[i]); } } int isEmpty( ) { if ( top== -1 ) return 1; else return 0; } int peek( ){ return stack[top]; } int main() { int choice,item; init_stack(); do { printf("Menu1.Push.2.Pop."); printf("3.Peek.4.Display.5.Exit."); printf("Your Choice: "); scanf("%d",&choice); switch(choice) { case 1:printf("Enter the element to push : "); scanf("%d",&item); push(item); break; case 2:item = pop(); printf("Element poped : %d",item); printf("Press a key to continue..."); getche(); break; case 3:item = peek(); printf("Element at top : %d",item); printf("Press a key to continue..."); getche(); break; case 4:display(); printf("Press a key to continue..."); getche(); break; case 5:exit(0); } }while(1); } Implementing Stack ADT using Array
20. struct s_node { int data; struct s_node *link; } *stack; void push(int j) { struct s_node *m; m=(struct s_node*)malloc(sizeof(struct s_node)); m->data= j ; m->link=stack; stack=m; return; } int pop( ) { struct s_node *temp=NULL; if(stack==NULL) { printf("STACK is Empty."); getch(); } else { int i=stack->data; temp = stack ; stack=stack->link; free(temp); return (i); } } int peek( ) { if(stack==NULL) { printf("STACK is Empty."); getch(); } else return (stack->data); } void display() { struct s_node *temp=stack; while(temp!=NULL) { printf("%d",temp->data); temp=temp->link; } } void main() { int choice,num,i; while(1) { printf(" MENU1. Push2. Pop3. Peek"); printf("4. Elements in Stack5. Exit"); printf("Enter your choice: "); scanf("%d",&choice); switch(choice) { case 1: printf("Element to be pushed:"); scanf("%d",&num); push(num); break; case 2: num=pop(); printf("Element popped: %d ",num); getch(); break; case 3: num=peek(); printf("Element peeked : %d ",num); getch(); break; case 4: printf("Elements present in stack : “ ): display();getch(); break; case 5: exit(1); default: printf("n Invalid Choice "); break; } } } Implementing Stack ADT using Linked List
21.
22. int queue[10] ,front, rear ; void init_queue() { front = rear = -1 ; } void addq ( int item ){ if ( rear == 9 ) { printf("Queue is full"); return ; } rear++ ; queue [ rear ] = item ; if ( front == -1 )front = 0 ; } int delq( ){ int data ; if ( front == -1 ) { printf("Queue is Empty"); return 0; } data = queue[front] ; queue[front] = 0 ; if ( front == rear ) front = rear = -1 ; else front++ ; return data ; } void display() { int i; if(front==-1) printf("Queue is empty."); else { printf("Elements are : "); for (i=front;i<=rear;i++) printf("%5d",queue[i]); } } int main() { int ch,num; init_queue(); do { printf("MENU1. Add to Queue”); printf(“2. Delete form Queue"); printf("3. Display Queue4. Exit."); printf("Your Choice: "); scanf("%d",&ch); switch(ch) { case 1: printf("Enter an element : "); scanf("%d",&num); addq(num);break; case 2: num=delq(); printf("Element deleted : %d",num); break; case 3: display(); break; case 4: exit(0); default: printf("Invalid option.."); } }while(1); } Implementing Queue ADT using Array
23. struct q_node { int data; struct q_node *next; }*rear,*front; void init_queue() { rear=NULL; front=NULL; } void addq(int item) { struct q_node *t; t=(struct q_node*)malloc(sizeof(struct q_node)); t->data=item; t->next=NULL; if(front==NULL) rear=front=t; else { rear->next=t; rear=rear->next; } } int delq() { struct q_node *temp; if(front==NULL) { printf("Queue is empty."); return 0; } else { int num = front->data; temp = front; front=front->next; free(temp); return num; } } void display() { struct q_node *temp=front; if(front==NULL) printf("Queue is empty."); else { printf("Elements in Queue :"); while(temp!=NULL) { printf("%5d",temp->data); temp=temp->next; } } } int main() { int ch,num; init_queue(); do { printf("MENU1. Add2. Delete"); printf("3. Display Queue4. Exit."); printf("Your Choice: "); scanf("%d",&ch); switch(ch) { case 1: printf("Enter an element : "); scanf("%d",&num); addq(num);break; case 2: num=delq(); printf("Element deleted : %d",num); break; case 3: display(); break; case 4: exit(0); default:printf("Invalid option.."); } }while(1); } Implementing Queue ADT using Liked List
24.
25. #define STACKSIZE 20 typedef struct { int top; char items[STACKSIZE]; }STACK; /*pushes ps into stack*/ void push(STACK *sptr, char ps) { if(sptr->top == STACKSIZE-1) { printf("Stack is full"); exit(1); } else sptr->items[++sptr->top]= ps; } char pop(STACK *sptr) { if(sptr->top == -1) { printf("Stack is empty"); exit(1); } else return sptr->items[sptr->top--]; } int main() { int i; STACK s; char x, y, E[20] ; s.top = -1; /* Initialize the stack is */ printf("Enter the Infix Expression:"); scanf("%s",E); for(i=0;E[i] != '';i++) { x= E[i]; /* Consider all lowercase letter from a to z are operands */ if(x<='z' && x>='a') printf("%c",x); else if(x == '(') push(&s ,x); else if( x == ')‘ ){ y=pop(&s) ; while(y != '(') { printf("%c",y); y=pop(&s) ; } } else { if(s.top ==-1 || s.items[s.top] == '(') push(&s ,x); else { /* y is the top operator in the stack*/ y = s.items[s.top]; /* precedence of y is higher/equal to x*/ if( y=='*' || y=='/'){ printf("%c", pop(&s)); push(&s ,x); } else if ( y=='+' || y=='-') /* precedence of y is equal to x*/ if( x=='+' || x=='-') { printf("%c", pop(&s)); push(&s ,x); } /* precedence of y is less than x*/ else push(&s ,x); } } } while(s.top != -1) printf("%c",pop(&s)); } In-Fix To Post-Fix convertion
26. #include<stdio.h> #include<ctype.h> #include<math.h> float stack[10]; int top=-1; void push(char c) { stack[++top]=c; } float pop() { float n; n=stack[top--]; return (n); } float evaluate(char expr[], float data[]) { int j=0; float op1=0,op2=0; char ch; while(expr[j]!='') { ch = expr[j]; if(isalpha(expr[j])) { push(data[j]); } else { op2=pop(); op1=pop(); switch(ch) { case '+':push(op1+op2);break; case '-':push(op1-op2);break; case '*':push(op1*op2);break; case '/':push(op1/op2);break; case '^':push(pow(op1,op2)); break; } } j++; } return pop(); } int main() { int j=0; char expr[20]; float number[20],result; printf("Enter a post fix expression : "); gets(expr); while(expr[j]!='') { if(isalpha(expr[j])) { fflush(stdin); printf("Enter number for %c : ",expr[j]); scanf("%f",&number[j]); } j++; } result = evaluate(expr,number); printf("The result of %s is %f",expr,result); } Evaluation of Post-Fix Expression