SlideShare a Scribd company logo
Write a program that sort a link list in Ascending(Larger to
Smaller) using bubble sort algorithm.
#include<iostream>
using namespace std;
class node
{
public :
int a;
node *next;
};
main()
{
char b;
int count,i,j,k;
i=j=k=0;
count=1;
node *head,*cur,*fur,*temp;
head=NULL;
while(1)
{
if(head==NULL)
{
fur=new node;
cout<<"n Enter the data you want to store : ";
cin>>fur->a;
fur->next=NULL;
head=fur;
cur=fur;
}
else
{
fur= new node;
cout<<"n Enter the new data you want to store : ";
cin>>fur->a;
fur->next=NULL;
cur->next=fur;
cur=fur;
}
cout<<"n Enter f for add another node : ";
cin>>b;
if(b!='f')
{
cur->next=NULL;
break;
}
count++;
}
cout<<"n The Total nodes are : "<<count;
cout<<"n The data before sorting are n";
cur=head;
while(cur!=NULL)
{
cout<<" The data is : "<<cur->a<<endl;
cur=cur->next;
}
cur=head;
temp=cur;
int s;
while(cur!=NULL)
{
while(temp->next!=NULL)
{
if((temp->a )> (temp->next->a))
{
s=temp->a;
temp->a=temp->next->a;
temp->next->a=s;
}
temp=temp->next;
}
temp=head;
cur=cur->next;}
cout<<"nThe list is sorted n";
cout<<"n The data is shown on screenn";
cur=head;
while(cur!=NULL)
{
cout<<" The data is : "<<cur->a<<endl;
cur=cur->next;
}
system("pause");
}

More Related Content

DOCX
Implementation of k-means clustering algorithm in C
PPTX
Tokens expressionsin C++
PPTX
Smart pointers
PPTX
Variadic functions
PPTX
Pointer to function 1
PPTX
C programming enumeration
PPTX
Encapsulation C++
PDF
Scd type2 through informatica
Implementation of k-means clustering algorithm in C
Tokens expressionsin C++
Smart pointers
Variadic functions
Pointer to function 1
C programming enumeration
Encapsulation C++
Scd type2 through informatica

What's hot (20)

PPTX
Chapter 16 Dictionaries
PPTX
C++ concept of Polymorphism
DOCX
C++ file
PDF
Structures and Pointers
PPTX
Python comments and variables.pptx
PPTX
Decision making and branching
PDF
C pdf
PDF
C# simplified
PPT
pre processor directives in C
PPTX
Exception handling c++
PPTX
Pointer in c program
PPTX
Phone Book project in Data Structure C
PPT
Oracle database - Get external data via HTTP, FTP and Web Services
ODP
eBPF maps 101
PPTX
Functions in c
PPT
Decision Making and Branching in C
PPTX
Break,Pass and Continue.pptx
PPTX
C Programming Unit-2
DOCX
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
PDF
Constructor and Destructor
Chapter 16 Dictionaries
C++ concept of Polymorphism
C++ file
Structures and Pointers
Python comments and variables.pptx
Decision making and branching
C pdf
C# simplified
pre processor directives in C
Exception handling c++
Pointer in c program
Phone Book project in Data Structure C
Oracle database - Get external data via HTTP, FTP and Web Services
eBPF maps 101
Functions in c
Decision Making and Branching in C
Break,Pass and Continue.pptx
C Programming Unit-2
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Constructor and Destructor
Ad

Similar to Bubble in link list (20)

TXT
PDF
In the class we extensively discussed a node class called IntNode in.pdf
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
PDF
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
DOCX
Linked lists
PPTX
UNIT I- Sesgfnbghnghnghmghmhgmhmhsion 4.pptx
PPT
PPT
PDF
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
PDF
In C++Write a recursive function to determine whether or not a Lin.pdf
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PDF
Implement a priority queue using a doublyLinked-cpp where the node wit.pdf
PDF
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
PDF
Sorting with Linked-List Write a c++ program to read a series of integ.pdf
PDF
888678123317368915236 #include stdio.h #include stdlib.h.pdf
PDF
Hi,Please fidn the Answer.Sorting,h is Header .pdf
PDF
you will implement some sorting algorithms for arrays and linked lis.pdf
PDF
Data Structures in C++I am really new to C++, so links are really .pdf
DOCX
#include stdafx.h using namespace std; #include stdlib.h.docx
PDF
In the class we extensively discussed a node class called IntNode in.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Linked lists
UNIT I- Sesgfnbghnghnghmghmhgmhmhsion 4.pptx
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Implement a priority queue using a doublyLinked-cpp where the node wit.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Sorting with Linked-List Write a c++ program to read a series of integ.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
Data Structures in C++I am really new to C++, so links are really .pdf
#include stdafx.h using namespace std; #include stdlib.h.docx
Ad

More from university of Gujrat, pakistan (20)

PPTX
Change management
PPTX
Latest Trends in Digital Marketing
PPTX
Code of ethics and professional conduct (1)
PPTX
Certification accreditation and licensure (1)
PPTX
biggest technology trends
PPTX
Freedom of information (1)
PPTX
Individual cognition ppt (1)
PDF
Top 10 highest (1)
PPTX
creativity and imagination
PPTX
Brainstorming 078 (1)
PPTX
speeh-artificial intelligemce
PPTX
Pp dealing with problem complexity (1)
PPTX
Vision of artificial intelligence (1)
PPTX
Entrepreneurship (1)
PPTX
Role of professional societies
PPTX
Dealing with culticultural environment (1)
PPTX
Dealing with problem complexity (1)
PPTX
cyber security and cyber crime
Change management
Latest Trends in Digital Marketing
Code of ethics and professional conduct (1)
Certification accreditation and licensure (1)
biggest technology trends
Freedom of information (1)
Individual cognition ppt (1)
Top 10 highest (1)
creativity and imagination
Brainstorming 078 (1)
speeh-artificial intelligemce
Pp dealing with problem complexity (1)
Vision of artificial intelligence (1)
Entrepreneurship (1)
Role of professional societies
Dealing with culticultural environment (1)
Dealing with problem complexity (1)
cyber security and cyber crime

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Understanding_Digital_Forensics_Presentation.pptx
sap open course for s4hana steps from ECC to s4
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Programs and apps: productivity, graphics, security and other tools
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Bubble in link list

  • 1. Write a program that sort a link list in Ascending(Larger to Smaller) using bubble sort algorithm. #include<iostream> using namespace std; class node { public : int a; node *next; }; main() { char b; int count,i,j,k; i=j=k=0; count=1; node *head,*cur,*fur,*temp; head=NULL; while(1) { if(head==NULL) { fur=new node; cout<<"n Enter the data you want to store : ";
  • 2. cin>>fur->a; fur->next=NULL; head=fur; cur=fur; } else { fur= new node; cout<<"n Enter the new data you want to store : "; cin>>fur->a; fur->next=NULL; cur->next=fur; cur=fur; } cout<<"n Enter f for add another node : "; cin>>b; if(b!='f') { cur->next=NULL; break; } count++; }
  • 3. cout<<"n The Total nodes are : "<<count; cout<<"n The data before sorting are n"; cur=head; while(cur!=NULL) { cout<<" The data is : "<<cur->a<<endl; cur=cur->next; } cur=head; temp=cur; int s; while(cur!=NULL) { while(temp->next!=NULL) { if((temp->a )> (temp->next->a)) { s=temp->a; temp->a=temp->next->a; temp->next->a=s; } temp=temp->next; } temp=head;
  • 4. cur=cur->next;} cout<<"nThe list is sorted n"; cout<<"n The data is shown on screenn"; cur=head; while(cur!=NULL) { cout<<" The data is : "<<cur->a<<endl; cur=cur->next; } system("pause"); }