SlideShare a Scribd company logo
Implementation in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
struct node
{
Int data;
Int key;
Struct node *next;
};
Struct node *head = NULL;
Struct node *current = NULL;
//display the list
Void print List ()
{
Struct node *par = head;
Print ("n [“);
//start from the beginning
While (par! = NULL)
{
Print ("(%d, %d) ", par->key, ptr->data);
Par = par->next;
}
Print (“]");
}
//insert link at the first location
Void insert First (int key, int data)
{
//create a link
Struct node *link = (struct node*) mallow (size of
(struct node));
Link->key = key;
Link->data = data;
//point it to old first node
Link->next = head;
//point first to new first node
Head = link;
}
//delete first item
Struct node* delete First ()
{
//save reference to first link
Struct node *Templin = head;
//mark next to first link as first
Head = head->next;
//return the deleted link
Return Templin;
}
//is list empty
Bolo is Empty ()
{
Return head == NULL;
}
int length()
{
int length = 0;
struct node *current;
for(current = head; current != NULL; current = current-
>next)
{
length++;
}
return length;
}
//find a link with given key
struct node* find(int key){
//start from the first link
struct node* current = head;
//if list is empty
if(head == NULL)
{
return NULL;
}
//navigate through list
while(current->key != key){
//if it is last node
if(current->next == NULL){
return NULL;
}else {
//go to next link
current = current->next;
}
}
//if data found, return the current Link
return current;
}
//delete a link with given key
struct node* delete(int key){
//start from the first link
struct node* current = head;
struct node* previous = NULL;
//if list is empty
if(head == NULL){
return NULL;
}
//navigate through list
while(current->key != key){
//if it is last node
if(current->next == NULL){
return NULL;
}else {
//store reference to current link
previous = current;
//move to next link
current = current->next;
}
}
//found a match, update the link
if(current == head) {
//change first to point to next link
head = head->next;
}else {
//bypass the current link
previous->next = current->next;
}
return current;
}
void sort(){
int i, j, k, tempKey, tempData ;
struct node *current;
struct node *next;
int size = length();
k = size ;
for ( i = 0 ; i < size - 1 ; i++, k-- ) {
current = head ;
next = head->next ;
for ( j = 1 ; j < k ; j++ ) {
if ( current->data > next->data ) {
tempData = current->data ;
current->data = next->data;
next->data = tempData ;
tempKey = current->key;
current->key = next->key;
next->key = tempKey;
}
current = current->next;
next = next->next;
}
}
}
void reverse(struct node** head_ref) {
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL) {
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head_ref = prev;
}
main() {
insertFirst(1,10);
insertFirst(2,20);
insertFirst(3,30);
insertFirst(4,1);
insertFirst(5,40);
insertFirst(6,56);
print("Original List: ");
//print list
printList();
while(!isEmpty()){
struct node *temp = deleteFirst();
print("nDeleted value:");
print("(%d,%d) ",temp->key,temp->data);
}
print("nList after deleting all items: ");
printList();
insertFirst(1,10);
insertFirst(2,20);
insertFirst(3,30);
insertFirst(4,1);
insertFirst(5,40);
insertFirst(6,56);
print("nRestored List: ");
printList();
print("n");
struct node *foundLink = find(4);
if(foundLink != NULL){
print("Element found: ");
print("(%d,%d) ",foundLink->key,foundLink->data);
print("n");
}else {
print("Element not found.");
}
delete(4);
print("List after deleting an item: ");
printList();
print("n");
foundLink = find(4);
if(foundLink != NULL){
print("Element found: ");
print("(%d,%d) ",foundLink->key,foundLink->data);
print("n");
}else {
print("Element not found.");
}
print("n");
sort();
print("List after sorting the data: ");
printList();
reverse(&head);
print("nList after reversing the data: ");
printList();
}
If we compile and run the above program then it would produce
following result −
Output
Original List:
[ (6,56) (5,40) (4,1) (3,30) (2,20) (1,10) ]
Deleted value:(6,56)
Deleted value:(5,40)
Deleted value:(4,1)
Deleted value:(3,30)
Deleted value:(2,20)
Deleted value:(1,10)
List after deleting all items:
[ ]
Restored List:
[ (6,56) (5,40) (4,1) (3,30) (2,20) (1,10) ]
Element found: (4,1)
List after deleting an item:
[ (6,56) (5,40) (3,30) (2,20) (1,10) ]
Element not found.
List after sorting the data:
[ (1,10) (2,20) (3,30) (5,40) (6,56) ]
List after reversing the data:
[ (6,56) (5,40) (3,30) (2,20) (1,10) ]

More Related Content

What's hot

Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
13. dynamic allocation
13. dynamic allocation13. dynamic allocation
13. dynamic allocation
웅식 전
 
Java весна 2013 лекция 3
Java весна 2013 лекция 3Java весна 2013 лекция 3
Java весна 2013 лекция 3
Technopark
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
Raihan Bin-Mofidul
 

What's hot (20)

Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 studentsProgram: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
 
Concatenation of two strings using class in c++
Concatenation of two strings using class in c++Concatenation of two strings using class in c++
Concatenation of two strings using class in c++
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
13. dynamic allocation
13. dynamic allocation13. dynamic allocation
13. dynamic allocation
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Java весна 2013 лекция 3
Java весна 2013 лекция 3Java весна 2013 лекция 3
Java весна 2013 лекция 3
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
 
Lab 13
Lab 13Lab 13
Lab 13
 
Team 10
Team 10Team 10
Team 10
 
Function basics
Function basicsFunction basics
Function basics
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
week-20x
week-20xweek-20x
week-20x
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
Kill the DBA
Kill the DBAKill the DBA
Kill the DBA
 

Similar to Implement of c &amp; its coding programming by sarmad baloch

Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
poddaranand1
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
ankitmobileshop235
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
acarolyn
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
sooryasalini
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
jyothimuppasani1
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
facevenky
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
tienlivick
 

Similar to Implement of c &amp; its coding programming by sarmad baloch (20)

Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
 
i nsert+in+ link list
i nsert+in+ link listi nsert+in+ link list
i nsert+in+ link list
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 

More from Sarmad Baloch

More from Sarmad Baloch (20)

Pakistan International cricket stadiums in ADVANCE DATABASE Managment System ...
Pakistan International cricket stadiums in ADVANCE DATABASE Managment System ...Pakistan International cricket stadiums in ADVANCE DATABASE Managment System ...
Pakistan International cricket stadiums in ADVANCE DATABASE Managment System ...
 
Positive matrix by sarmad baloch
Positive matrix by sarmad balochPositive matrix by sarmad baloch
Positive matrix by sarmad baloch
 
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
 
Bnak reconciliation statement by sarmad baloch
Bnak reconciliation statement by sarmad balochBnak reconciliation statement by sarmad baloch
Bnak reconciliation statement by sarmad baloch
 
Introduction of object oriented analysis &amp; design by sarmad baloch
Introduction of object oriented analysis &amp; design by sarmad balochIntroduction of object oriented analysis &amp; design by sarmad baloch
Introduction of object oriented analysis &amp; design by sarmad baloch
 
Security_saftety_privacy of computer by sarmad baloch
Security_saftety_privacy of computer by sarmad balochSecurity_saftety_privacy of computer by sarmad baloch
Security_saftety_privacy of computer by sarmad baloch
 
E commerce (introduction to computer) by sarmad baloch
E commerce (introduction to computer) by sarmad balochE commerce (introduction to computer) by sarmad baloch
E commerce (introduction to computer) by sarmad baloch
 
Programming languages and programme development of computer by sarmad baloch
Programming languages and programme development of computer by sarmad balochProgramming languages and programme development of computer by sarmad baloch
Programming languages and programme development of computer by sarmad baloch
 
Introduction to computer &amp; its applications by sarmad baloch
Introduction to computer &amp; its applications by sarmad balochIntroduction to computer &amp; its applications by sarmad baloch
Introduction to computer &amp; its applications by sarmad baloch
 
Accounting principle & concept by sarmad baloch
Accounting principle & concept by sarmad balochAccounting principle & concept by sarmad baloch
Accounting principle & concept by sarmad baloch
 
The functions of modal auxiliary verbs by sarmad baloch
The functions of modal auxiliary verbs by sarmad balochThe functions of modal auxiliary verbs by sarmad baloch
The functions of modal auxiliary verbs by sarmad baloch
 
Integrator &amp; diferentiator amplifier presentation by sarmad baloch
Integrator &amp; diferentiator amplifier presentation by sarmad balochIntegrator &amp; diferentiator amplifier presentation by sarmad baloch
Integrator &amp; diferentiator amplifier presentation by sarmad baloch
 
Ms powerpoint 2007 presentation by sarmad baloch
Ms powerpoint 2007 presentation by sarmad balochMs powerpoint 2007 presentation by sarmad baloch
Ms powerpoint 2007 presentation by sarmad baloch
 
Semiconductor materials and pn junction by sarmad baloch
Semiconductor materials and pn junction by sarmad balochSemiconductor materials and pn junction by sarmad baloch
Semiconductor materials and pn junction by sarmad baloch
 
Introduction of BJT,types of Diodes by sarmad baloch
Introduction of BJT,types of Diodes by sarmad balochIntroduction of BJT,types of Diodes by sarmad baloch
Introduction of BJT,types of Diodes by sarmad baloch
 
Pn junction diode by sarmad baloch
Pn junction diode by sarmad balochPn junction diode by sarmad baloch
Pn junction diode by sarmad baloch
 
Difference b/w BRITISH vs AMERICAN Language by sarmad khosa
Difference b/w BRITISH vs AMERICAN Language by sarmad khosaDifference b/w BRITISH vs AMERICAN Language by sarmad khosa
Difference b/w BRITISH vs AMERICAN Language by sarmad khosa
 
ACTIVE & PASSIVE ELECTRONICS by sarmad khosa
ACTIVE & PASSIVE ELECTRONICS by sarmad khosaACTIVE & PASSIVE ELECTRONICS by sarmad khosa
ACTIVE & PASSIVE ELECTRONICS by sarmad khosa
 
MICROSOFT WORD 2007 FULL PRESENTATION BY sarmad khosa
MICROSOFT WORD 2007 FULL PRESENTATION BY sarmad khosaMICROSOFT WORD 2007 FULL PRESENTATION BY sarmad khosa
MICROSOFT WORD 2007 FULL PRESENTATION BY sarmad khosa
 
Types of DIODES Basic electronics by sarmad khosa
Types of DIODES Basic electronics by sarmad khosaTypes of DIODES Basic electronics by sarmad khosa
Types of DIODES Basic electronics by sarmad khosa
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

Implement of c &amp; its coding programming by sarmad baloch

  • 1. Implementation in C #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdbool.h> struct node { Int data; Int key; Struct node *next; }; Struct node *head = NULL; Struct node *current = NULL; //display the list Void print List () { Struct node *par = head; Print ("n [“); //start from the beginning While (par! = NULL) { Print ("(%d, %d) ", par->key, ptr->data); Par = par->next; } Print (“]"); } //insert link at the first location Void insert First (int key, int data) {
  • 2. //create a link Struct node *link = (struct node*) mallow (size of (struct node)); Link->key = key; Link->data = data; //point it to old first node Link->next = head; //point first to new first node Head = link; } //delete first item Struct node* delete First () { //save reference to first link Struct node *Templin = head; //mark next to first link as first Head = head->next; //return the deleted link Return Templin; } //is list empty Bolo is Empty () { Return head == NULL; } int length()
  • 3. { int length = 0; struct node *current; for(current = head; current != NULL; current = current- >next) { length++; } return length; } //find a link with given key struct node* find(int key){ //start from the first link struct node* current = head; //if list is empty if(head == NULL) { return NULL; } //navigate through list while(current->key != key){ //if it is last node if(current->next == NULL){ return NULL; }else { //go to next link current = current->next; }
  • 4. } //if data found, return the current Link return current; } //delete a link with given key struct node* delete(int key){ //start from the first link struct node* current = head; struct node* previous = NULL; //if list is empty if(head == NULL){ return NULL; } //navigate through list while(current->key != key){ //if it is last node if(current->next == NULL){ return NULL; }else { //store reference to current link previous = current; //move to next link current = current->next; } } //found a match, update the link if(current == head) {
  • 5. //change first to point to next link head = head->next; }else { //bypass the current link previous->next = current->next; } return current; } void sort(){ int i, j, k, tempKey, tempData ; struct node *current; struct node *next; int size = length(); k = size ; for ( i = 0 ; i < size - 1 ; i++, k-- ) { current = head ; next = head->next ; for ( j = 1 ; j < k ; j++ ) { if ( current->data > next->data ) { tempData = current->data ; current->data = next->data; next->data = tempData ; tempKey = current->key; current->key = next->key; next->key = tempKey; }
  • 6. current = current->next; next = next->next; } } } void reverse(struct node** head_ref) { struct node* prev = NULL; struct node* current = *head_ref; struct node* next; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } *head_ref = prev; } main() { insertFirst(1,10); insertFirst(2,20); insertFirst(3,30); insertFirst(4,1); insertFirst(5,40); insertFirst(6,56); print("Original List: "); //print list printList();
  • 7. while(!isEmpty()){ struct node *temp = deleteFirst(); print("nDeleted value:"); print("(%d,%d) ",temp->key,temp->data); } print("nList after deleting all items: "); printList(); insertFirst(1,10); insertFirst(2,20); insertFirst(3,30); insertFirst(4,1); insertFirst(5,40); insertFirst(6,56); print("nRestored List: "); printList(); print("n"); struct node *foundLink = find(4); if(foundLink != NULL){ print("Element found: "); print("(%d,%d) ",foundLink->key,foundLink->data); print("n"); }else { print("Element not found."); } delete(4); print("List after deleting an item: "); printList(); print("n"); foundLink = find(4); if(foundLink != NULL){
  • 8. print("Element found: "); print("(%d,%d) ",foundLink->key,foundLink->data); print("n"); }else { print("Element not found."); } print("n"); sort(); print("List after sorting the data: "); printList(); reverse(&head); print("nList after reversing the data: "); printList(); } If we compile and run the above program then it would produce following result − Output Original List: [ (6,56) (5,40) (4,1) (3,30) (2,20) (1,10) ] Deleted value:(6,56) Deleted value:(5,40) Deleted value:(4,1) Deleted value:(3,30) Deleted value:(2,20) Deleted value:(1,10) List after deleting all items: [ ] Restored List: [ (6,56) (5,40) (4,1) (3,30) (2,20) (1,10) ] Element found: (4,1) List after deleting an item: [ (6,56) (5,40) (3,30) (2,20) (1,10) ] Element not found. List after sorting the data: [ (1,10) (2,20) (3,30) (5,40) (6,56) ] List after reversing the data:
  • 9. [ (6,56) (5,40) (3,30) (2,20) (1,10) ]