zoukankan      html  css  js  c++  java
  • 数组排列数组里的正数和负数排序

    本篇文章是一篇关于数组排列的帖子

        每日一道理
    漫漫人生路,谁都难免会遭遇各种失意或厄运。在凄风苦雨 惨雾愁云的考验面前,一个强者,是不会向命运低头的。风再冷,不会永远不息;雾再浓,不会经久不散。风息雾散,仍是阳光灿烂。
    # coding: gb2312
    #将数组里的正数排在数组的后面,正数排在数组的后面。但不改变原先正数和正数的排列次序。
    #例:input: -5,2,-3, 4,-8,-9, 1, 3,-10;output: -5, -3, -8, -9, -10, 2, 4, 1, 3。
    
    
    A = [-5,2,-3, 4,-8,-9,1, 3,-10];
    print A
    length = len(A)
    i = length - 1
    
    
    while A[i] >= 0: i = i - 1
    
    
    j = i
    while j >= 0:
        if A[j] >= 0:
            t = A[j]
            k = j + 1
            while k < length and A[k] < 0:
                A[k - 1] = A[k]
                k += 1
            A[k - 1] = t
            i = j
        j -= 1
    print 'result:'
    print A

    文章结束给大家分享下程序员的一些笑话语录: 姿势要丰富,经常上百度!

    --------------------------------- 原创文章 By
    数组和排列
    ---------------------------------

  • 相关阅读:
    [Leetcode]@python 89. Gray Code
    [Leetcode]@python 88. Merge Sorted Array.py
    [Leetcode]@python 87. Scramble String.py
    [Leetcode]@python 86. Partition List.py
    [leetcode]@python 85. Maximal Rectangle
    0523BOM
    0522作业星座
    0522dom
    0520
    0519作业
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3153351.html
Copyright © 2011-2022 走看看