This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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--; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAX 10 | |
#define ERRORSTACKEMPTY -2 | |
#define ERRORSTACKFULL -1 | |
typedef struct{ | |
int item[MAX]; | |
int top; | |
}Stack; | |
int push(Stack *p,int x); |
OlderNewer