Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define INDICE_INVALIDE 0
- typedef double ELEMENT;
- typedef struct {
- int nombre_elements;
- ELEMENT elements[100];
- }LISTE_TABLEAU;
- int liste_pleine(LISTE_TABLEAU *liste)
- {
- /// zedt'ha ena khater profa ma ketbethhech
- return liste->nombre_elements ==100;
- }
- void liste_initialiser(LISTE_TABLEAU *liste)
- {
- liste->nombre_elements=0;
- }
- ELEMENT liste_element(LISTE_TABLEAU *liste, int indice)
- {
- if (indice >=0 && indice < liste->nombre_elements)
- return liste->elements[indice];
- else
- {
- printf("Erreur d'indice\n");
- return 0;
- }
- }
- int liste_ajouter(LISTE_TABLEAU* liste, ELEMENT e)
- {
- int indice;
- if(!liste_pleine(liste))
- {
- indice= liste->nombre_elements;
- liste->elements[indice]=e;
- liste->nombre_elements++;
- }
- else
- indice= INDICE_INVALIDE;
- return indice;
- }
- int liste_inserer(LISTE_TABLEAU *liste, int indice, ELEMENT e)
- {
- int i, resultat;
- if (!liste_pleine(liste))
- if (indice >= 0 && indice <= liste->nombre_elements)
- {
- for (i= liste->nombre_elements;i>indice;i--)
- liste->elements[i]=liste->elements[i-1];
- liste->nombre_elements++;
- liste->elements[indice]=e;
- resultat= indice;
- }
- else
- resultat= INDICE_INVALIDE;
- else
- resultat= INDICE_INVALIDE;
- return resultat;
- }
- int liste_supprimer(LISTE_TABLEAU *liste, int indice)
- {
- int i,resultat;
- if (indice >=0 && indice < liste->nombre_elements)
- {
- for (i = indice +1; i < liste->nombre_elements; i++)
- liste->elements[i-1]= liste->elements[i];
- liste->nombre_elements--;
- resultat=indice;
- }
- else
- resultat= INDICE_INVALIDE;
- return resultat;
- }
- int liste_nombre_elements(LISTE_TABLEAU *liste)
- {
- /// zedt'ha ena khater profa ma ketbethhech
- return liste->nombre_elements;
- }
- void afficher_liste(LISTE_TABLEAU *liste)
- {
- int i,nombre_elements;
- nombre_elements= liste_nombre_elements(liste);
- printf("{");
- for (i =0; i<nombre_elements; i++)
- {
- if (i>0)
- printf(", ");
- printf("%lg",liste_element(liste,i));
- }
- printf("}");
- }
- int main()
- {
- LISTE_TABLEAU *liste;
- int n,x;
- ELEMENT e;
- // all the code she wrote page 1-16 (Listes : Implémentation par les tableaux)
- printf("What Size List ya got:\n");
- liste_initialiser(liste);
- scanf("%d",&n);
- printf("Fill In The List:\n");
- for (int a=0;a<n;a++)
- {
- scanf("%lf",&e);
- x=liste_ajouter(liste,e);
- }
- int answer;
- do
- {
- /// system("cls");
- printf("\n\nPick One\n\t1: Add an element to the end of the list.\n\t2: Add an element to a specific position.\n\t3: Delete an element by position.\n\t4: Print List.\n\t0:Stop.\n");
- scanf("%d",&answer);
- switch(answer)
- {
- case 1:
- system("cls");
- printf("type element: ");
- scanf("%lf",&e);
- x=liste_ajouter(liste,e);
- break;
- case 2:
- system("cls");
- printf("type element and position:\n");
- scanf("%lf%d",&e,&x);
- x=liste_inserer(liste,x,e);
- break;
- case 3:
- system("cls");
- printf("type position of the element you want to delete: ");
- scanf("%d",&x);
- x=liste_supprimer(liste,x);
- break;
- case 4:
- system("cls");
- printf("_______________________________________\n");
- afficher_liste(liste);
- printf("\n_______________________________________\n");
- break;
- case 0:
- system("cls");
- break;
- default:
- system("cls");
- system("color 4");
- ///printf(“\033[0;31m”);
- printf("ERROR: You Have Picked An Non Existent Option...\nClick On Any Button To Retry...|");
- getch();
- system("color 7");
- system("cls");
- ///printf(“\033[0m”);
- }
- }while(answer!=0);
- system("color 5");
- printf("Thanks..");
- }
Advertisement
Add Comment
Please, Sign In to add comment