#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;
}
Learn C programming from scratch with our comprehensive tutorial series. Master the fundamentals, explore advanced concepts, and unleash your coding potential. Build a strong programming foundation with our easy-to-follow C programming tutorial. From data types to functions, arrays to pointers, we've got you covered.
Pages
▼
Wednesday
Insertion Sort C code | C Program Examples
Friday
Program to Convert Uppercase Characters to Lowercase in C
Here's a C program to convert uppercase characters to lowercase with output and proper explanation. This program uses C concepts like While Loop, Strings in C, Gets Function and Putchar Function.
Thursday
What is Putchar() function in C with Syntax and Example
Putchar() function prints or writes a character to standard output (monitor). This function takes one character as argument and writes that character on standard output.
Tuesday
C program for Bubble Sort | C Program Examples
#include<stdio.h>
#include<conio.h>
void bubble(int a[],int n)
{
int i,j,t;
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}//end for 1.
}//end function.
void main()
{
int a[100],n,i;
clrscr();
printf("\n\n Enter integer value for total no.s of elements to be sorted: ");
scanf("%d",&n);
for( i=0;i<=n-1;i++)
{ printf("\n\n Enter integer value for element no.%d : ",i+1);
scanf("%d",&a[i]);
}
bubble(a,n);
printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)
printf("%3d",a[i]);
}
Output will be as Following
Enter integer value for total no.s of elements to be sorted: 6
Enter integer value for element no.1 : 89
Enter integer value for element no.2 : -4
Enter integer value for element no.3 : -67
Enter integer value for element no.4 : 5
Enter integer value for element no.5 : 78
Enter integer value for element no.6 : 11
Finally sorted array is: -67 -4 5 11 78 89