Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:27:50+00:00 2026-05-31T11:27:50+00:00

sort([ [30,100], [10,11] ], X). gets X = [[10,11],[30,100]] How can I sort only

  • 0
sort([ [30,100], [10,11] ], X).

gets

X = [[10,11],[30,100]]

How can I sort only by the first index of each sublist?

i.e

X = [[10,100], [30, 11]]

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:27:51+00:00Added an answer on May 31, 2026 at 11:27 am

    The below is my untested code.. there may be one/two cosmetic errors… The input list is split into two based on the head value on the list and the resulted two lists are recursively processed to finally result the sorted output.

    sort(Input,Output):-sort(Input,[],Output).
    
    sort([],SortedOut,SortedOut).
    sort([[Index1,Index2]|Tail],SortedBig,Out):-
        split(Tail,[Index1,Index2],LessList,BigList),
        !,sort(BigList,SortedBig,NewSort),
        sort(LessList,[[Index1,Index2]|NewSort],Out).
    
    split([],[_D],[],[]).
    split([[Index1,Index2]|Rem],[Index21,Index22],[[Index1,Index1]|L1],L2):-
        Index1<Index21,
        !,split(Rem,[Index21,Index22],L1,L2).
    split([[Index1,Index2]|Rem],[Index21,Index22],L1,[[Index1,Index1]|L2]):-
        !,split(Rem,[Index21,Index22],L1,L2).
    

    Try this and let me know…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary: a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 } I want to sort this
...@Sort bit) AS SELECT .............. and I want to Order only if Sort =
I am trying to make a sort of progress bar that gets filled, with
I have a Mongo DB column which contains values of the sort 1001,100 and
I've found several questions that are sort of similar to mine, but not 100%.
How can I sort an array as the one shown below with jquery's own
I have an array that gets its values from a text file. Each line
I wrote this code, as a sort of lookahead. int main() { char a[100];
How can I can sort based on a key word? I have a kind-of
Sort of a methods/best practices question here that I am sure has been addressed,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.