Help with single Sorted LinkedList with Initializer List

1
2
SortedList<T>::SortedList(initializer_list<T> e){
}

Anyone to explain how to /help me make a single Sorted LinkedList using pointer Nodes? [:)] Have homework due tonight and can't start because I have no idea how to make this -.-

This is where I started

(Yes, I know TERRIBLE coding practices with intcheck and countera, I have finals and I'm just trying to slop something together)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
SortedList<T>::SortedList(initializer_list<T> e){
    head_= new Node<T>(*e.begin());
    
    long intcheck = 0;
    long countera = 0;
    T old;
    
    for (auto x : e){  
        if(intcheck > 0){
            Node<T>* curr = new Node<T>(old);
            if(countera == 0){
                head_->next_ = new Node<T>(x);
                countera = 1;
            }else{
            curr->next_ = new Node<T>(x);
            }
        }        
        old = x;
        intcheck = 1;
    }
}

It's not sorted and it only correctly creates the head_ node.
Last edited on
Have you written the function to insert a new value into SortedList<T> ?
Topic archived. No new replies allowed.