pub fn push_into(&mut self, data: T, index: Option<i32>) {
        match self.0 {
            // decoupled as (<T, LinkedList<T>>) because is a tuple
            Some((_, ref mut child)) => {
                match index {
                    Some(i) => {
                        // if index is 0, push to front
                        if i == 0 {
                            self.push_front(data)
                        } else if i >= 1 {
                            // If index is 1 or higher, find parent LinkedList and insert into it.
                            child.push_into(data, Some(i-1))
                        }
                    },
                    _ => self.push_back(data),
                }
            },
            None => self.push_front(data),
        }
    }
/// Added param, to pass a index to insert new object.
/// param is a Optional, if user does not define a number
/// the new LinkedList will be inserted at end of LinkedList
Added param, to pass a index to insert new object.
param is a Optional, if user does not define a number
the new LinkedList will be inserted at end of LinkedList
Added param to pass a index to insert new object . param is a Optional if user does not define a number the new LinkedList will be inserted at end of LinkedList
pub fn push_into(&mut self, data: T, index: Option<i32>) {
        match self.0 {
            // decoupled as (<T, LinkedList<T>>) because is a tuple
            Some((_, ref mut child)) => {
                match index {
                    Some(i) => {
                        // if index is 0, push to front
                        if i == 0 {
                            self.push_front(data)
                        } else if i >= 1 {
                            // If index is 1 or higher, find parent LinkedList and insert into it.
                            child.push_into(data, Some(i-1))
                        }
                    },
                    _ => self.push_back(data),
                }
            },
            None => self.push_front(data),
        }
    }
pub fn push_into ( & mut self , data : T , index : Option < i32 > ) { match self . 0 { // decoupled as (<T, LinkedList<T>>) because is a tuple Some ( ( _ , ref mut child ) ) => { match index { Some ( i ) => { // if index is 0, push to front if i == 0 { self . push_front ( data ) } else if i >= 1 { // If index is 1 or higher, find parent LinkedList and insert into it. child . push_into ( data , Some ( i - 1 ) ) } } , _ => self . push_back ( data ) , } } , None => self . push_front ( data ) , } }
Added param, to pass a index to insert new object.
Added param to pass a index to insert new object .
&mut self
data
T
index
Option<i32>
&mut self
data
T
index
Option<i32>