title: Compiler shows abort called
body: <p>I'm trying to delete a node in a singly linked list in a given position.When i submit this code all the test cases are success.But except one and the compiler shows abort called.When i googled it it shows resource exceeded.Is there is any other way to optimize this code to reduce the resource usage.
  I have written my code inside SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* head, int position) function.</p>
  <p>You’re given the pointer to the head node of a linked list and the position of a node to delete. Delete the node at the given position and return the head node. A position of 0 indicates head, a position of 1 indicates one node away from the head and so on. The list may become empty after you delete the node.</p>
  <p>Input Format</p>
  <p>You have to complete the deleteNode(SinglyLinkedListNode* llist, int position) method which takes two arguments - the head of the linked list and the position of the node to delete. You should NOT read any input from stdin/console. position will always be at least 0 and less than the number of the elements in the list.</p>
  <p>The first line of input contains an integer
  , denoting the number of elements in the linked list.
  The next lines contain an integer each in a new line, denoting the elements of the linked list in the order.
  The last line contains an integer</p>
  <p>denoting the position of the node that has to be deleted form the linked list.</p>
  <p>Constraints</p>
  <p>, where is the element of the linked list.</p>
  <p>Output Format
  Delete the node at the given position and return the head of the updated linked list. Do NOT print anything to stdout/console.</p>
  <p>The code in the editor will print the updated linked list in a single line separated by spaces.</p>
  <pre><code>  #include &lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  class SinglyLinkedListNode {
      public:
          int data;
          SinglyLinkedListNode *next;
  
          SinglyLinkedListNode(int node_data) {
              this-&gt;data = node_data;
              this-&gt;next = nullptr;
          }
  };
  
  class SinglyLinkedList {
      public:
          SinglyLinkedListNode *head;
          SinglyLinkedListNode *tail;
  
          SinglyLinkedList() {
              this-&gt;head = nullptr;
              this-&gt;tail = nullptr;
          }
  
          void insert_node(int node_data) {
              SinglyLinkedListNode* node = new SinglyLinkedListNode(node_data);
  
              if (!this-&gt;head) {
                  this-&gt;head = node;
              } else {
                  this-&gt;tail-&gt;next = node;
              }
  
              this-&gt;tail = node;
          }
  };
  
  void print_singly_linked_list(SinglyLinkedListNode* node, string sep, ofstream&amp; fout) {
      while (node) {
          fout &lt;&lt; node-&gt;data;
  
          node = node-&gt;next;
  
          if (node) {
              fout &lt;&lt; sep;
          }
      }
  }
  
  void free_singly_linked_list(SinglyLinkedListNode* node) {
      while (node) {
          SinglyLinkedListNode* temp = node;
          node = node-&gt;next;
  
          free(temp);
      }
  }
  
  // Complete the deleteNode function below.
  
  /*
   * For your reference:
   *
   * SinglyLinkedListNode {
   *     int data;
   *     SinglyLinkedListNode* next;
   * };
   *
   */
  SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* head, int position) {
     int i = 0;
  
     SinglyLinkedListNode* temp = new SinglyLinkedListNode(2);
      SinglyLinkedListNode* c;
      SinglyLinkedListNode* p;
      c = head;
      p = head;
  
      for(;i!=position;p=c,c=c-&gt;next,i++);
      p-&gt;next = c-&gt;next;
  
      delete c;
      
      return head;
  
  
     
  
   
  
  
  }
  
  int main()
  </code></pre>