Sort by

recency

|

714 Discussions

|

  • + 0 comments
    public static  Node insert(Node head,int data) {
            //Complete this method
            
            Node current = head;
            if (head == null)
                head = new Node(data);
            else{
                while(current.next != null){
                    current = current.next;
                }
                    current.next = new Node(data);
            }
            return head;
        }
    
  • + 0 comments

    Why do the typescript problems never have the implementations? There's no node class

  • + 0 comments

    I kinda hacked it I guess, by using self field. Though it happened cause I didn't watch the video and didn't understand what was required of me and why my intuitional approach yielded result reversal to demanded

    def insert(self, head, data):
            node = Node(data)
            if head is None:
                self.prev = node
                return node
            else:
                self.prev.next = node
                self.prev = node
            return head`
  • + 0 comments

    Solution in C#, using recursion:

    public static Node insert(Node head,int data)
    {
        if (head == null)
        {
            head = new Node(data);
            return head;
        }
        var newHead = insert(head.next, data);
    
        head.next= newHead;
    
        return head;
    }
    
  • + 0 comments

    In C++

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int n;
        cin >> n;
        
        vector<int> f(n);
        
        for(int i = 0; i < f.size(); i++){
            cin >> f[i];
        }
        
        for(int i = 0; i < f.size(); i++){
            cout << f[i] << " ";
        }
    }
    

    `