Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include <stdlib.h>
#include <time.h>
#define ANSI_COLOR_RED "x1b[31m"
#define ANSI_COLOR_GREEN "x1b[32m"
#define ANSI_COLOR_YELLOW "x1b[33m"
#define ANSI_COLOR_BLUE "x1b[34m"
#define ANSI_COLOR_MAGENTA "x1b[35m"
#define ANSI_COLOR_CYAN "x1b[36m"
#define ANSI_COLOR_RESET "x1b[0m"
/* --------- Declaration --------- */
struct list {
int n;
struct list *svt;
};
/* --------- AFFICHAGE --------- */
void display(struct list *tete){
struct list *tmp = tete;
if (tmp !=NULL)
{
int test=0;
int i;
//printf("------------------------------------------n");
int length =taille(tete);
int z ;
for (z = 1; z <= length; z++)
{
printf("------");
printf(" ");
}
printf("n");
while (test != 1) {
printf("| %d |---> ",tmp -> n);
if (tmp -> svt == NULL)
{
test = 1;
}
tmp = tmp -> svt;
}
printf("END :) n");
for (z = 1; z <= length; z++)
{
printf("------");
printf(" ");
}
printf("n");
} else {
printf("Chaine Vide XD n");
}
}
/* --------- TAILLE --------- */
int taille(struct list *tete){
struct list *tmp = tete;
int i =0;
if (tmp !=NULL)
{
int test=0;
while (test != 1) {
if (tmp -> svt == NULL)
test = 1;
i++;
tmp = tmp -> svt;
}
} else {
i=0;
}
//printf("proc length %dn", i);
return i;
}
/* --------- Q1 --------- */
struct list *addbegin(struct list *tete , int n){
struct list *nouv = malloc(sizeof(struct list));
if ( nouv != NULL){
nouv -> n = n;
nouv -> svt = NULL;
if (tete == NULL) {
tete = nouv;
} else {
nouv -> svt = tete;
tete = nouv;
}
}
//display(tete);
return(tete);
}
struct list *addend(struct list *tete , int n){
struct list *nouv = malloc(sizeof(struct list));
if ( nouv != NULL){
nouv -> n = n;
nouv -> svt = NULL;
if (tete == NULL) {
tete = nouv;
} else {
struct list *tmp = tete ;
while(tmp -> svt != NULL )
tmp = tmp -> svt;
tmp -> svt = nouv;
}
}
return(tete);
}
struct list *fifo(struct list *tete){
struct list *del = tete;
if ( tete != NULL){
tete = tete -> svt;
free(del);
}
return(tete);
}
struct list *rond_robin(struct list *tete, int q){
struct list *temp = tete;
struct list *destroy = tete;
if ( tete != NULL){
int i ;
for (i = 1; i <= q; i++)
{
temp -> n -=1;
if (temp -> n == 0)
{
destroy = temp;
temp = temp -> svt;
tete = temp;
free(destroy);
}
}
}
//display(tete);
return(tete);
}
struct list *SGF(struct list *tete){
if ( tete != NULL){
/* hewes */
struct list *der_cible = NULL;
struct list *cible = tete;
struct list *amount = NULL;
struct list *temp = tete;
while(temp != NULL){
if (cible -> n > temp -> n)
{
cible = temp;
der_cible = amount;
}
amount = temp;
temp= temp -> svt;
}
printf("la valeur min est%dn",cible -> n );
der_cible -> svt = cible -> svt;
free(cible);
}
return(tete);
}
void delay(int i){
clock_t start,end;
start=clock();
while(((end=clock())-start)<=i*CLOCKS_PER_SEC);
}
void main(){
struct list *list_h = NULL;
struct list *list_m = NULL;
struct list *list_l = NULL;
int r,i;
while (1){
for (i = 0; i < 3; ++i)
{
r = (rand()%9)+1;
list_h = addend(list_h,r);
r = (rand()%9)+1;
list_m = addend(list_m,r);
r = (rand()%2)+1;
list_l = addend(list_l,r);
}
// FIFO
display(list_h);
//SGF
display(list_m);
//ROND ROBIN
display(list_l);
printf(ANSI_COLOR_RED"--------------------( FIFO )---------------------n"ANSI_COLOR_RESET);
display(list_h);
list_h = fifo(list_h);
list_h = fifo(list_h);
display(list_h);
printf(ANSI_COLOR_RED"--------------------( SJF )---------------------n"ANSI_COLOR_RESET);
display(list_m);
list_m = SGF(list_m);
list_m = SGF(list_m);
display(list_m);
printf(ANSI_COLOR_RED"--------------------( ROND ROBIN )---------------------n"ANSI_COLOR_RESET);
display(list_l);
list_l = rond_robin(list_l,4);
display(list_l);
delay(3);
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team