Coder Social home page Coder Social logo

basemax / splitlinkedlistc Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 26 KB

This is a simple implementation of a linked-list in C with a few helper functions for merging two or three linked-lists, splitting a linked list into two or three parts, and sorting a linked-list (recursive and non-recursive)

License: GNU General Public License v3.0

C 100.00%
c linked-list linkedlist algorithm algorithm-challenges algorithms algorithms-and-data-structures algorithms-datastructures merge merge-linked-list merge-linkedlist split-linked-list split-linkedlist

splitlinkedlistc's Introduction

Split Linked-List C

This is a simple implementation of a linked-list in C with a few helper functions for merging two or three linked-lists, splitting a linked list into two or three parts, and sorting a linked-list (recursive and non-recursive)

There are a lot of functions in this project. You can use them in your project:

  • Add a node to the linked-list
  • Create a node
  • Create a linked-list
  • Split a linked-list into two linked-lists
  • Split a linked-list into three linked-lists
  • Merge two linked-lists into one linked-list
  • Merge three linked-lists into one linked-list
  • Sort a linked-list
  • Sort a linked-list (recursive)
  • Print a linked-list

How to use

// Split the linked list into two linked lists
struct LinkedList* list1 = createLinkedList();
struct LinkedList* list2 = createLinkedList();
split2LinkedList(list, list1, list2);

// Print linked lists
printf("List: ");
printList(list);

printf("List 1: ");
printList(list1);

printf("List 2: ");
printList(list2);

// Merge two linked lists
struct LinkedList* merge1 = createLinkedList();
merge2LinkedList(merge1, list1, list2);

printf("Merge 1: ");
printList(merge1);

// Split the linked list into three linked lists
list1 = createLinkedList();
list2 = createLinkedList();
struct LinkedList* list3 = createLinkedList();
split3LinkedList(list, list1, list2, list3);

// Print linked lists
printf("List: ");
printList(list);

printf("List 1: ");
printList(list1);

printf("List 2: ");
printList(list2);

printf("List 3: ");
printList(list3);

// Merge three linked lists
struct LinkedList* merge2 = createLinkedList();
merge3LinkedList(merge2, list1, list2, list3);

printf("Merge 2: ");
printList(merge2);

printf("Sorted merge 1: ");
sortLinkedListRecursive(merge2->head);
printList(merge1);

printf("Sorted merge 2: ");
sortLinkedList(merge1);
printList(merge2);

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

Copyright (c) 2022, Max Base

splitlinkedlistc's People

Stargazers

Sabbir Ahmed avatar Ryota Sakai avatar Daniel Bruno avatar

Watchers

 avatar

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.