DEV Community

Ganga Sri V
Ganga Sri V

Posted on

Move All negative element to End

Problem Statement:
Given an unsorted array arr[ ] having both negative and positive integers. The task is to place all negative elements at the end of the array without changing the order of positive elements and negative elements.

My Approach:
1.I created a new array called temp of the same size as the original array.
2.First, I go to the original array and copied all positive numbers to temp.
3.Then, I go to the array again and copied all negative numbers to temp.
4.Finally, I copied all numbers from temp back to the original array.

Methods Used:
Extra array
Single traversal
Stable order preservation

Top comments (0)