I’m pleased to publish this insertion sort implementation on single linked lists developed with my collegue Rigel.
It’s a nice experiment in asymptotic complexity of O(n^3). The high complexity is due to the necessity of retrieving the neighbours of the node handled, a difficult operation when using single linked lists.
Download: Insertion Sort on Single Linked Lists
As assignment for Data Structures and Algorithms course, we had to work with a modified version of the quicksort algorithm. It came obvious that for modifying a qsort you need to implement it
It is difficult to find a clear quicksort algorithm implemented, so I wrote it.
Here is the generic C implementation of the Quicksort Algorithm, which sorts an array in place, following the Divide And Conquer design.
Download: quicksort qsort in C language
Interesting methods (look at the source code for comments):
int partition
( int A
[],
int left,
int right
) {
int pivot;
pivot = A
[right
];
while(1){
while( A
[right
] > pivot
){
right–;
}
while( A
[left
] < pivot
){
left++;
}
if( left < right
){
swap
(A,left,right
);
}else{
return left;
}
}
}
void quicksort( int A[], int left, int right){
int m;
if( left < right ) {
m = partition( A, left, right);
quicksort( A, left, m-1);
quicksort( A, m+1, right);
}
}
As you see, there is nothing optimized in this implementation. It just looks elegant and easy to be understood.
If you would like to have a more optimized version of this algorithm, take a look at this one.
Today I wrote a new version of my summary posted here. The new version covers more topics, here is the updated list:
- Memory portions assigned to a program (code area, heap / dynamic memory area), execution stack
- How code is loaded in Java
- The Activation Record (AR) and function calls
- Abbrevations (AR, RV, RA, SP, N/E, @, ??, arb)
- Examples on method calls and activation records usage
- Declaraion vs. Definition of a variable, the scope of a variable, blocks
- Scope Activation Record (SAR), Static Link (SL), the role of SL
- The extent/lifetime of a variable
- Dynamic memory allocation and handling
- Dynamic vs. Static memory allocation
- Dynamic memory scope and extent
- Accessing dynamic memory
- Classes and Objects in detail, object instantiation
- Memory Management issues
- Objects vs. Variables (definitions)
- Methods of Objects
- Class Attributes
- The null value
- Parameters (formal, actual), parameters passing (by reference, by value)
- Constructors and Inline Initialization
- Constructor’s call