Coder Social home page Coder Social logo

roba-asd's Introduction

roba-asd

#include <string>
#include <iostream>

using namespace std;

struct Node {
    int info;
    Node* next;
};

typedef  Node* List;


List insertAt(List list, int position, int e) {
    if (!list && position == 0) {
        list = new Node {e, nullptr};
        return list;
    }
    if (list && position == 0) {
        list = new Node {e, list};
        return list;
    }
    int count = 0;
    auto current = list;
    auto previous = list;
    while (current && count < position) {
        count += 1;
        previous = current;
        current = current->next;
    }
    if (count == position) {
        previous->next = new Node {e, current};
        return list;
    }
    throw "";

}













template <class F>
List removeIf(List l, F function) {
    auto begin = l;
    auto previous = l;
    int i = 0;
    while (l) {
        if (function(l->info, i)) {
            if (begin==l) {
                auto toDelete = l;
                l = l->next;
                begin = l;
                delete toDelete;
            } else {
                auto toDelete = l;
                previous->next = l->next;
                l = l->next;
                delete toDelete;
            }
        }   
        i += 1;
        previous = l;
        if (l) l = l->next;
    }
    return begin;
    // throw "not found";
}

roba-asd's People

Contributors

remorses 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.