SlideShare a Scribd company logo
1 of 3
Download to read offline
How to copy all the things in linked list, paste them into a not empty file and delete all the things
the file used had?
in C
thanks.
Solution
#include
#include
struct node
{
int data;
struct node *next;
};
void removeDuplicates(struct node *start)
{
struct node *ptr1, *ptr2, *dup;
ptr1 = start;
while(ptr1 != NULL && ptr1->next != NULL)
{
ptr2 = ptr1;
while(ptr2->next != NULL)
{
if(ptr1->data == ptr2->next->data)
{
dup = ptr2->next;
ptr2->next = ptr2->next->next;
free(dup);
}
Else
{
ptr2 = ptr2->next;
}
}
ptr1 = ptr1->next;
}
}
void push(struct node** head_ref, int new_data);
void printList(struct node *node);
int main()
{
struct node *start = NULL;
push(&start, 10);
push(&start, 11);
push(&start, 12);
push(&start, 11);
push(&start, 11);
push(&start, 12);
push(&start, 10);
printf(" Linked list before removing duplicates ");
printList(start);
removeDuplicates(start);
printf(" Linked list after removing duplicates ");
printList(start);
getchar();
}
void push(struct node** head_ref, int new_data)
{
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}
void printList(struct node *node)
{
while(node != NULL)
{
printf("%d ", node->data);
node = node->next;
}
}

More Related Content

Similar to How to copy all the things in linked list, paste them into a not emp.pdf

using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
excellentmobilesabc
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
nitinarora01
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdf
footstatus
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
ajayadinathcomputers
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
The Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdfThe Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdf
anushkaent7
 
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
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 

Similar to How to copy all the things in linked list, paste them into a not emp.pdf (20)

using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
DS - Application of List
DS - Application of ListDS - Application of List
DS - Application of List
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
 
Template LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdfTemplate LinkedList;I am using templates to make some linkedLists.pdf
Template LinkedList;I am using templates to make some linkedLists.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
Implement of c & its coding programming by sarmad baloch
Implement of c & its coding  programming by sarmad balochImplement of c & its coding  programming by sarmad baloch
Implement of c & its coding programming by sarmad baloch
 
The Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.pdfThe Program to find out the middle of a given linked listclass Lin.pdf
The Program to find out the middle of a given linked listclass Lin.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
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 

More from ivylinvaydak64229

Every year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdfEvery year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdf
ivylinvaydak64229
 
Describe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdfDescribe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdf
ivylinvaydak64229
 
Analyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdfAnalyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdf
ivylinvaydak64229
 
Collect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdfCollect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdf
ivylinvaydak64229
 
Assume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdfAssume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdf
ivylinvaydak64229
 
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdfA New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
ivylinvaydak64229
 
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdfA protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
ivylinvaydak64229
 
What were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdfWhat were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdf
ivylinvaydak64229
 
write two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdfwrite two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdf
ivylinvaydak64229
 

More from ivylinvaydak64229 (20)

For the hypothesis test H0 = 5 against H1 5 with variance unkn.pdf
For the hypothesis test H0  = 5 against H1   5 with variance unkn.pdfFor the hypothesis test H0  = 5 against H1   5 with variance unkn.pdf
For the hypothesis test H0 = 5 against H1 5 with variance unkn.pdf
 
Early in 2017 scientists have discovered a new family of eukaryotic b.pdf
Early in 2017 scientists have discovered a new family of eukaryotic b.pdfEarly in 2017 scientists have discovered a new family of eukaryotic b.pdf
Early in 2017 scientists have discovered a new family of eukaryotic b.pdf
 
Do you believe great leaders are born or madeSolutioni believe.pdf
Do you believe great leaders are born or madeSolutioni believe.pdfDo you believe great leaders are born or madeSolutioni believe.pdf
Do you believe great leaders are born or madeSolutioni believe.pdf
 
Every year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdfEvery year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdf
 
Describe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdfDescribe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdf
 
Describe the Darwinian theory of evolutionDescribe the Darwi.pdf
Describe the Darwinian theory of evolutionDescribe the Darwi.pdfDescribe the Darwinian theory of evolutionDescribe the Darwi.pdf
Describe the Darwinian theory of evolutionDescribe the Darwi.pdf
 
Consider any organization where you’ve worked in the past, where you.pdf
Consider any organization where you’ve worked in the past, where you.pdfConsider any organization where you’ve worked in the past, where you.pdf
Consider any organization where you’ve worked in the past, where you.pdf
 
Analyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdfAnalyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdf
 
Collect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdfCollect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdf
 
Assume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdfAssume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdf
 
Are the following events SOURCES or USES of cashDecrease in Accou.pdf
Are the following events SOURCES or USES of cashDecrease in Accou.pdfAre the following events SOURCES or USES of cashDecrease in Accou.pdf
Are the following events SOURCES or USES of cashDecrease in Accou.pdf
 
A. What are two advantages that the use of green fluorescent protein.pdf
A. What are two advantages that the use of green fluorescent protein.pdfA. What are two advantages that the use of green fluorescent protein.pdf
A. What are two advantages that the use of green fluorescent protein.pdf
 
A species has a diploid number of 2n. Meiosis I fails during spermato.pdf
A species has a diploid number of 2n. Meiosis I fails during spermato.pdfA species has a diploid number of 2n. Meiosis I fails during spermato.pdf
A species has a diploid number of 2n. Meiosis I fails during spermato.pdf
 
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdfA New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
 
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdfA protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
 
What were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdfWhat were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdf
 
write two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdfwrite two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdf
 
Where might you find the gametophytes of… Where might you find the g.pdf
Where might you find the gametophytes of… Where might you find the g.pdfWhere might you find the gametophytes of… Where might you find the g.pdf
Where might you find the gametophytes of… Where might you find the g.pdf
 
What single , unique characteristic of a protist would be conside.pdf
What single , unique characteristic of a protist would be conside.pdfWhat single , unique characteristic of a protist would be conside.pdf
What single , unique characteristic of a protist would be conside.pdf
 
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdfWhat are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

How to copy all the things in linked list, paste them into a not emp.pdf

  • 1. How to copy all the things in linked list, paste them into a not empty file and delete all the things the file used had? in C thanks. Solution #include #include struct node { int data; struct node *next; }; void removeDuplicates(struct node *start) { struct node *ptr1, *ptr2, *dup; ptr1 = start; while(ptr1 != NULL && ptr1->next != NULL) { ptr2 = ptr1; while(ptr2->next != NULL) { if(ptr1->data == ptr2->next->data) { dup = ptr2->next; ptr2->next = ptr2->next->next; free(dup); } Else { ptr2 = ptr2->next; } } ptr1 = ptr1->next;
  • 2. } } void push(struct node** head_ref, int new_data); void printList(struct node *node); int main() { struct node *start = NULL; push(&start, 10); push(&start, 11); push(&start, 12); push(&start, 11); push(&start, 11); push(&start, 12); push(&start, 10); printf(" Linked list before removing duplicates "); printList(start); removeDuplicates(start); printf(" Linked list after removing duplicates "); printList(start); getchar(); } void push(struct node** head_ref, int new_data) { struct node* new_node = (struct node*) malloc(sizeof(struct node)); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node; } void printList(struct node *node) { while(node != NULL) { printf("%d ", node->data); node = node->next; }
  • 3. }