Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- #define NMAX 101
- void swap(int* a, int* b) {
- int tmp = *a;
- *a = *b;
- *b = tmp;
- }
- void moveNegsToStart(int n, int arr[]) {
- int j = 0;
- while (arr[j] < 0) {
- j++;
- }
- for (int i = j + 1; i < n; i++) {
- if (arr[i] < 0) {
- swap(&arr[i], &arr[j]);
- j++;
- while (arr[j] < 0) {
- j++;
- }
- }
- }
- }
- int main(void) {
- int n;
- assert(scanf_s("%d", &n));
- static int arr[NMAX];
- for (int i = 0; i < n; i++) {
- assert(scanf_s("%d", &arr[i]));
- }
- moveNegsToStart(n, arr);
- for (int i = 0; i < n; i++) {
- printf("%d ", arr[i]);
- }
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement