How do i keep a linked list sorted? How do i remove if more than 10 items? -
from node import node
-
-
probe = head
-
count = 0
-
while probe != None:
-
count += 1
-
probe = probe.next
-
return count
-
-
def insert(newName, newScore, head):
-
probe.next.score = newScore
-
if head is None:
-
head = newNode
-
else:
-
probe = head
-
while probe.next != None:
-
probe = probe.next
-
probe.next = newNode
-
return head
-
-
def printStructure(newName, newScore):
-
probe = head
-
while probe != None:
-
print "Name: ", probe.name,
-
print "Score: ", probe.score
-
probe = probe.next
-
-
def main():
-
head = None
-
-
head = insert("She-RA", 1088, head)
-
printStructure(head)
-
-
#Add ten nodes to the beginning of the linked structure
-
head = insert("He-MAN", 32464, head)
-
head = insert("Doc-Ock", 143322, head)
-
head = insert("Spidey", 6416, head)
-
head = insert("Superman", 63438, head)
-
head = insert("Arceus", 92515, head)
-
head = insert("Batman", 11986, head)
-
head = insert("Homer", 26712, head)
-
head = insert("F-ZERO", 833849, head)
-
insert("Dlew58", 999999, head)
-
print "Top Ten"
-
printStructure(head)
-
if __name__ == "__main__":
-
main()
-
1 1964
A linked list is not sorted, it is linked in some order. So if you have records with the values 'A', 'C', 'E', 'G', 'H' in the linked list and you wanted to add 'B', the next record number would then be 6, so record number 1 would point to 6 instead of 2, and record 6 would point to the second record to keep them in order.
How do i remove if more than 10 items?
It depends on if you are talking about memory or a file on disk. Generally you mark it as deleted, and simply remove the link to it, so the record that points to it would point to the record that it used to point to. Practically speaking, regenerating the linked list isn't necessary every time a record is deleted but is done after some threshold is reached. To regenerate the linked list, you would copy the records in the original list to a new memory location or file without copying the deleted records.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew Clark |
last post by:
*** post for FREE via your newsreader at post.newsfeed.com ***
it's been a while since i have poseted to this newsgroup, but for a long
time i was not programming at all. but now that i am out of...
|
by: Kieran Simkin |
last post by:
Hi all,
I'm having some trouble with a linked list function and was wondering if
anyone could shed any light on it. Basically I have a singly-linked list
which stores pid numbers of a process's...
|
by: dssuresh6 |
last post by:
Whether browsing forward or backward can be done using a singly linked
list. Is there any specific case where a doubly linked list is needed?
For people who say that singly linked list allows...
|
by: a |
last post by:
keep a list of read and unread items
hi guys
i m building an rss reader and i want you suggestions for datastructure
for keeping read and unread list for each use
i m assuming it will be very...
|
by: akadri1010 |
last post by:
I am new to Python programming..
Can anyone help me to write a simple Python program that creates a singly linked list and then prints the entries in it??
I know how to do in C?? But Python does...
|
by: joshd |
last post by:
Hello,
Im sorry if this question has been asked before, but I did search
before posting and couldnt find an answer to my problem. I have two
classes each with corresponding linked lists, list1...
|
by: sangram |
last post by:
how to delete last node of a Linked list if you only know the address
of last node.
thanks
sangram
|
by: Dongsheng Ruan |
last post by:
with a cell class like this:
#!/usr/bin/python
import sys
class Cell:
def __init__( self, data, next=None ):
self.data = data
|
by: CMoose |
last post by:
I'm trying to write a program that reads data from a text file and stores it into a doubly linked list. I then want to be able to edit or sort the list.
However, I'm having trouble getting started...
|
by: kalar |
last post by:
Hello.
we have this struct and we must to make a linked list
struct node {
char name;
char phone;
struct node *prevName; // previous node alphabetically
struct node *prevNumber; //...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |