Skip to content

Instantly share code, notes, and snippets.

View Pr3d4dor's full-sized avatar

Gianluca Bine Pr3d4dor

  • Brazil
View GitHub Profile
//Bubble sort function in c
void bubbleSort(int *vet,int n){
int i,j,aux;
for (i=0;i<n-1;i++){
for (j=0;j<n-i-1;j++){
if (vet[j]>vet[j+1]){
aux=vet[j];
vet[j]=vet[j+1];
vet[j+1]=aux;
}
//Selection sort function in c
void selectionSort(int *vet,int n){
int i,j,min,aux;
for (i=0;i<n-2;i++){
min=i;
for (j=i+1;j<n;j++){
if (vet[j]<vet[min])
min=j;
}
aux=vet[i];
//Insertion sort function in c
void insertionSort(int *vet,int n){
int i,j,temp;
for(i=1;i<n;i++){
temp=vet[i];
j=i-1;
while((j>=0)&&(vet[j]>temp)){
vet[j+1]=vet[j];
j--;
}
//Merge sort function in c
void mergeSort(int *vet,int *vetAux,int left,int right){
int middle;
if (left<right){
middle=(left+right)/2;
mergeSort(vet,vetAux,left,middle);
mergeSort(vet,vetAux,middle+1,right);
insert(vet,vetAux,left,middle+1,right);
}
}
//Sequential search function in c
int seqSearch(int *vet,int n,int x){
int i;
for (i=0;i<n;i++){
if (x==vet[i])
return 1;
}
}
//Binary search function in c
int binarySearch(int *vet,int n,int x){
//The vector needs to be ordered for the binary search work properly, you can use any sorting method.
bubbleSort(vet,n);
while (ini<=end){
middle=(ini+end)/2;
if (vet[middle]==x)
return 1;
if (vet[middle]<x)
ini=middle+1;
@Pr3d4dor
Pr3d4dor / Pong.c
Last active August 29, 2015 14:24
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define y 20
#define x 70
int main()
{
int i=0,j=0,ball_x=x/2,ball_y=y/2,p1_ini=7,p1_end=y-7,p2_ini=7,p2_end=y-7,control=0,move;
int movementballx=1,movementbally=1,pointsp1=0,pointsp2=0;
#include <stdio.h>
#include <stdlib.h>
//Stack.h is a header file that contains a abstract data type stack created to represent a stack, as the own name says
//Stack.h is here among the others gists
#include "Stack.h"
int main(){
int i;
Stack p;
char ex[MAX],aux=0,control=0;
iniStack(&p);
#define MAX 10
#define ERRORSTACKEMPTY -2
#define ERRORSTACKFULL -1
typedef struct{
int item[MAX];
int top;
}Stack;
int push(Stack *p,int x);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <stdbool.h>
#define LIN 7
#define COL 7
//Funcao para verificar se as coordenadas são validas
bool verificaCoordenadas(int x,int y){
int controle1=0,controle2=0;