#include <stdio.h>
#include <conio.h>
struct node{
int number;
struct node *next;
};
struct node *head = NULL;
/* insert a node directly at the right place in the linked list */
void insert_node(int value);
int main(void){
struct node *current = NULL;
struct node *next = NULL;
int test[] = {8, 3, 2, 6, 1, 5, 4, 7, 9, 0};
int i = 0;
/* insert some numbers into the linked list */
for(i = 0; i < i =" 0;">next != NULL){
printf("%4d\t%4d\n", test[i++], head->number);
head = head->next;
}
/* free the list */
for(current = head; current != NULL; current = next)
next = current->next, free(current);
return 0;
}
void insert_node(int value) {
struct node *temp = NULL;
struct node *one = NULL;
struct node *two = NULL;
if(head == NULL) {
head = (struct node *)malloc(sizeof(struct node *));
head->next = NULL;
}
one = head;
two = head->next;
temp = (struct node *)malloc(sizeof(struct node *));
temp->number = value;
while(two != NULL && temp->number <>number) {
one = one->next;
wo = two->next;
}
one->next = temp;
temp->next = two;
}
Wednesday
Insertion Sort C code | C Program Examples
Subscribe to:
Post Comments (Atom)
Labels
C Program Examples
For Loops
C Aptitude Questions
C Interview Questions with Answers
If Else in C
Nested Loops
Arrays in C
Modulus in C
While Loop
C Programming Tips
If in C
Arithmetic Operations
Auto Incrementing Operator ++
Break
C Programming Facts
Strings in C
C Concepts
Matrix in C
Float Data Type
Power Function pow()
Switch Case
gets Function in C
Entering Value in a Matrix
String Functions
C Operators
C++ Interview Questions with Answers
Continue in C
String Copy strcpy()
Trigonometry Examples
Auto Decrementing Operator --
CTYPE.H Header File in C
Division in C
Fibonacci Series
For Loop with No Body
GOTO Statement
Pointer in C
Sorting
String Length strlen()
Ternary Operator
Two Dimensional Arrays in C
Type Casting in C
Using Arrays as Pointers in C
Using Pointers as Arrays in C
C Header Files
Constructor
Destructor
Do While Loop
Finding Day of Given Date
Finding Leap Year
User Defined Functions in C

