Giter Club home page Giter Club logo

Hi there 👋

#include <stdio.h> #include <stdlib.h>

// Structure pour un élément de la liste chaînée struct Node { int data; struct Node* next; };

// Fonction pour ajouter un élément à la fin de la liste void append(struct Node** head, int value) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; newNode->next = NULL;

if (*head == NULL) {
    *head = newNode;
} else {
    struct Node* current = *head;
    while (current->next != NULL) {
        current = current->next;
    }
    current->next = newNode;
}

}

// Fonction pour supprimer un élément de la liste void delete(struct Node** head, int value) { if (*head == NULL) { return; }

struct Node* temp = *head;
if (temp->data == value) {
    *head = temp->next;
    free(temp);
    return;
}

while (temp->next != NULL && temp->next->data != value) {
    temp = temp->next;
}

if (temp->next == NULL) {
    return;
}

struct Node* toDelete = temp->next;
temp->next = toDelete->next;
free(toDelete);

}

// Fonction pour rechercher un élément dans la liste int search(struct Node* head, int value) { struct Node* current = head; while (current != NULL) { if (current->data == value) { return 1; // Trouvé } current = current->next; } return 0; // Non trouvé }

// Fonction pour afficher la liste void display(struct Node* head) { struct Node* current = head; while (current != NULL) { printf("%d ", current->data); current = current->next; } printf("\n"); }

// Exemple d'utilisation int main() { struct Node* myList = NULL;

append(&myList, 10);
append(&myList, 20);
append(&myList, 30);

printf("Liste initiale : ");
display(myList);

delete(&myList, 20);
printf("Après suppression de 20 : ");
display(myList);

printf("Recherche de 30 : %s\n", search(myList, 30) ? "Trouvé" : "Non trouvé");

return 0;

}

Native 's Projects

cli icon cli

GitHub’s official command line tool

community icon community

Public feedback discussions for: GitHub Mobile, GitHub Discussions, GitHub Codespaces, GitHub Sponsors, GitHub Issues and more!

innu38 icon innu38

Config files for my GitHub profile.innu38

ospo icon ospo

Open Source Program Office

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.