Skip to content

Instantly share code, notes, and snippets.

View jatinsharrma's full-sized avatar

Jatin Sharma jatinsharrma

  • India
View GitHub Profile
@jatinsharrma
jatinsharrma / SelectionSort.c
Created April 1, 2019 10:42
Sorting an array - Selection Sort
#include <stdio.h>
int SelectionSort(int array[], int size){
for (int i =0 ; i < size ; i++){
int small = array[i], index = i;
for (int j = i ; j<size ; j++){
if (array[j] < small){
small = array[j];
index = j;
}
@jatinsharrma
jatinsharrma / SelectionSortPointers.c
Created April 1, 2019 10:59
Selection Sort using pointers - call by reference
#include <stdio.h>
int swap(int* i, int* j){
int temp = *i;
*i = *j;
*j = temp;
}
int SelectionSort(int array[], int size){
for (int i =0 ; i < size ; i++){
@jatinsharrma
jatinsharrma / BubbleSort.c
Created April 1, 2019 11:14
Sorting an array - Bubble Sort
#include <stdio.h>
int swap(int* i, int* j){
int temp = *i;
*i = *j;
*j = temp;
}
int BubbleSort(int array[], int size){
for (int i =0 ; i < size-1 ; i++){
@jatinsharrma
jatinsharrma / InsertionSort.c
Created April 1, 2019 12:10
Sorting an array - Insertion Sort
#include <stdio.h>
int swap(int* i, int* j){
int temp = *i;
*i = *j;
*j = temp;
}
int InsertionSort(int array[], int size){
for (int i =1 ; i < size ; i++){
@jatinsharrma
jatinsharrma / StaticStack.c
Created April 3, 2019 09:32
Stack implantation
# include<stdio.h>
# define CAPACITY 5
int stack[CAPACITY], top = -1 ;
//Prototyping
void push(int);
int isFull(void);
void pop(void);
int isEmpty(void);
void peek(void);
@jatinsharrma
jatinsharrma / LinkedList.c
Last active April 15, 2019 18:55
Linked List implementation
#include<stdio.h>
#include<stdlib.h>
//Prototyping
void append(void);
void add_begin(void);
void add_after(void);
void delete_node(void);
void display(void);
int length(void);
@jatinsharrma
jatinsharrma / StaticQueue.c
Created April 3, 2019 19:17
Queue implementation using array
#include<stdio.h>
#include<stdlib.h>
# define CAPACITY 5
int queue[CAPACITY], top = -1, base = -1;
//prototyping
void enQueue(int);
int isEmpty(void);
int isFull(void);
@jatinsharrma
jatinsharrma / DoublyLinkedList.c
Created April 6, 2019 18:20
Doubly Linked List implementation
#include<stdio.h>
#include<stdlib.h>
//Prototyping
void append(void);
void add_begin(void);
void add_after(void);
void delete_node(void);
void display(void);
void reverse(void);
@jatinsharrma
jatinsharrma / Stack_LL.c
Last active April 6, 2019 19:47
Stack implementation using linked list
#include<stdio.h>
#include<stdlib.h>
//prottyping
void push(int);
int pop(void);
void traverse(void);
int length(void);
void delete(void);
//initialize
@jatinsharrma
jatinsharrma / BinaryTree.c
Created April 18, 2019 16:04
Binary Tree implementation in C
#include<stdio.h>
#include<stdlib.h>
// Initialization ----------------------------------------------------------------------------------
struct node {
int data;
struct node* left;
struct node* right;
};