473,396 Members | 2,151 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,396 software developers and data experts.

Neater method of creating a linked list

Hi. I would like to make a typedef for a structure which can be joined
up into a linked list. I include my code below. My code works, but I
have a vague suspicion that I could have declared my "spectrum" type in
a neater way. Is there a better way of doing the following?

Thanks in anticipation,

Ross-c

#include <stdlib.h>

typedef struct spectrum spectrum;

struct spectrum
{
double *magnitude;
double *phase;
int n;

double phaseNormalisation;
double magnitudeNormalisation;

spectrum *next;
};

spectrum *spectrum_make( double *data[], int N );
void spectrum_free( spectrum *s );

Nov 30 '05 #1
2 1285

Ross Clement (Email address invalid - do not use) schrieb:
Hi. I would like to make a typedef for a structure which can be joined
up into a linked list. I include my code below. My code works, but I
have a vague suspicion that I could have declared my "spectrum" type in
a neater way. Is there a better way of doing the following?


Yes.
It might be a good idea to write code for linked lists as such. Most
functions on lists work for list of spectrums as well as for list of
characters or list of luxury cars. One example would be reverse(),
another append(), that appends one list to another list. Others do need
helper functions, for example sort(), filter() or map().

Alternatively, switch to C++ and use some library, such as the STL,
where container data types are already available in all sizes and
shapes.

Nov 30 '05 #2
Ross Clement (Email address invalid - do not use) wrote:
Hi. I would like to make a typedef for a structure which can be joined
up into a linked list. I include my code below. My code works, but I
have a vague suspicion that I could have declared my "spectrum" type in
a neater way. Is there a better way of doing the following?

Thanks in anticipation,

Ross-c

#include <stdlib.h>

typedef struct spectrum spectrum;

struct spectrum
{
double *magnitude;
double *phase;
int n;

double phaseNormalisation;
double magnitudeNormalisation;

spectrum *next;
};

spectrum *spectrum_make( double *data[], int N );
void spectrum_free( spectrum *s );


Seperate the linked-list from the spectrum parts, ie

struct spectrum
{
double *magnitude;
double *phase;
int n;
double phaseNormalisation;
double magnitudeNormalisation;
};

struct list
{
void *payload;
struct list *next;
};

typedef void (*free_payload)(void *p);

struct list_info
{
free_payload free_fn;
struct list *first;
};

Nov 30 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
7
by: alternativa | last post by:
Hello, I'm a beginner in C programming and I have a problem that probably will seem trivial to most of you, however I can't find a solution... So, I have to write a data base - program should ask...
6
by: Suyash Upadhyay | last post by:
Hi All, As a beginner in Computer Programming, I decided to create Linked List using recursion, but I am not getting right answer. I think it is fundamentally correct, but I am stuck. ...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
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:
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.