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.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1223
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests