Bubble Sort Linked List

This is the place for queries that don't fit in any of the other categories.

Bubble Sort Linked List

Postby dezeray112 » Thu Dec 12, 2013 2:17 am

Hi, I am currently trying to program a singly linked list by sorting the nodes in ascending order using the Bubble Sort Algorithm in Python.

Code: Select all

def (sort):
a1=self.head
a2=a1.next
while a1 != None:
ap=self.head
ap2=ap.next
while ap:
if ap.val>ap2.val:
a1=ap2
a2=ap
ap=ap.next
ap2=ap.next
self.head=a1
a1=self.head
print a1.val
print l1



The code I've implemented was able to change the nodes, however it was not able to loop through and it will not add in the next value as it only prints out 2 values. Can someone tell me is there something that I am missing in my code?
Last edited by micseydel on Thu Dec 12, 2013 5:51 am, edited 1 time in total.
Reason: Locked.
dezeray112
 
Posts: 1
Joined: Thu Dec 12, 2013 2:12 am

Re: Bubble Sort Linked List

Postby micseydel » Thu Dec 12, 2013 6:05 am

You should read this. We need to see your indentation.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 2993
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 7 guests