473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

deleting node from linked list

i was wondering if anyone could help me under stands the basics of deleting a node from a linked list\

my programs has something like this:

typedef struct car{
int mass;
int x;
int y;
struct car *nextptr;
struct car *lastptr;
} car;


and there are about 500 nodes in my linked list and i need help to find a way to deleted nodes from this linked list, more precisely, when x and y are equal for any of the nodes i want to delete the node with the smaller mass.
Mar 14 '10 #1
1 3632
jkmyoung
2,057 Expert 2GB
How are you detecting that you have duplicates? If you can prevent it, don't add new nodes that are duplicates. When adding, check if there is a duplicate, and if so replace it!

Otherwise:
Assuming you have a list like
a -> b -> c -> ... -> z

There are several cases.
1. Remove the head.
- Change the head pointer from a to b,
- delete a,
2. Remove from the middle, say b.
- Change the previous node's pointer from b to c
- Remove b.
3. Remove the last.
- Change the previous' node's pointer from z to null.
- Change the last node pointer from z to y.
- Remove z.

Assuming you can tell when two nodes are equal.

If your concern hasn't been covered, please post back with a more specific section.
Mar 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Fabio | last post by:
Hi everyone, Is there anybody who can suggest me a link where I can find information about 'Persistent linked list' ? I need to implement a linked list where every node is a structure like the...
0
by: Andrew | last post by:
Does a linked list in C require that the head node allocate memory the size of the structures in the node? Or can you just set the head node structure equal to 0? I have tried creating lists both...
10
by: Daniel Vukadinovic | last post by:
OK, here's the deal. I'd like to delete the list.Here's what I do: node* p_temp = p_beginning; while (p_beginning != 0) { p_beginning = p_beginning->p_next; delete p_beginning; }
16
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
7
nabh4u
by: nabh4u | last post by:
hi, i have a double linked list containing some elements and i have a vector which stores the address of the elements in the list (pointer to the list). i want to delete a value from the list,like...
4
by: dabbakal | last post by:
Hello, am a new member and this is my first posting. Having benefited from lot of posting i decided to join. But currently am trying to solve an exercise and it is proven difficult for me. I have...
10
by: ac.c.2k7 | last post by:
Hello Everyone, The solution to this is to copy the data from the next node into this node and delete the next node!. 1. But if the node to be deleted is the last node. Then what should we do ?...
42
by: Avon | last post by:
Hello there. I have a problem regarding node deletion in singly-linked lists in C. What happens is that I can't hold the previous node efficiently. Here is the code I use. struct lista *search...
10
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
5
bluechimera
by: bluechimera | last post by:
Of course this isn't the whole program.... but it is a rather large slice of code. Yes I am in college, I am not asking for someone to do this for me.. I think that is rather stupid... you don't...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.