Total members 11895 |It is currently Sun Dec 22, 2024 3:22 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





insertion sort inside the list using C++

cpp code
void insertSortList(LIST *L, int x) 
{
NODE *nextptr,*previus,*newptr;
nextptr=L->head;
previus=nextptr;
if(nextptr==NULL)
{
newptr=(NODE*) malloc(sizeof(NODE));
newptr->data=x;
newptr->next=L->head;
L->head=newptr;
L->size++;
return;
}
else if(x<L->head->data)
{
newptr=(NODE*) malloc(sizeof(NODE));
newptr->data=x;
newptr->next=L->head;
L->head=newptr;
return;
}
else{
while ((nextptr != NULL )&& ((nextptr->data) < x ))
{
previus = nextptr;
nextptr = nextptr->next;
}
newptr=(NODE *)malloc(sizeof(NODE));
newptr->data=x;
newptr->next=nextptr;
previus->next=newptr;
L->size++;
return;
}
}
void deleteNode(LIST *L, int x)
{
NODE *nextptr, *previus;
nextptr = L->head;
if (nextptr->data == x)
{ //the head is treated separately
L->head = nextptr->next;
L->size--;
free(nextptr);
return;
}
else
{
while (nextptr != NULL)
{ //find x and delete it
if (nextptr->data == x)
{ //value found
Previus->next =nextptr->next;
free(nextptr);
L->size--;
return;
}
previus = nextptr; //use *previus as the previous position pointer
nextptr = nextptr->next;
}
}
}//delete





Author:
Moderator
User avatar Posts: 47
Have thanks: 1 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : list insertion sorting code in c++
 Java Insertion Sort Code     -  
 Incomplete code for array sorting and merging     -  
 How to write a code for sorting array of 100 number in C++     -  
 Quicksort implementation C++ Code-Integers-Sorting     -  
 quicksort algorithm implementation java code- array sorting     -  
 balloon sort algorithm C++ implementation code-sorting array     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 Linked List C++ Code Implementation     -  
 Read list of files in java I/O code     -  
 can u check tis code to perform union & intersection of list     -  



Topic Tags

C++ Sorting
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com