Solved

Naming Singly Linked List

Posted on 1997-10-10
1
175 Views
Last Modified: 2006-11-17
I am trying to figure out how to name a singly linked list.
For example, if I am doing a quadratic polynomial and I have defined a structure such as this:

typedef struct poly_node *poly_pointer;
typedef struct poly_node
{
int coefficient;
int exponent;
poly_pointer link;
};

Then in the main part of the program. I want to ask the user what is the name for a certain polynomial which may look like this:

main ()
{
printf("Enter a name for this polynomial: ");
scanf("%s", name);
.....

}

The question is how do I make the reference in naming that polynomial? I don't want to put the name in the struct because each node will want to have a name. The thing I am trying to do is that...I just want to make a reference to that named polynomial such that if I want to add two polynomial together and call that function to add:

addpoly(a,b);

where a and b are individual polynomial. how do I approach this problem???
0
Comment
Question by:ricco
1 Comment
 

Accepted Solution

by:
nate091597 earned 50 total points
ID: 1255827
Add another structure, e.g.,

typedef struct polynomial
{
    char name[50];
    poly_pointer link;
} polynomial;

Then you can write

polynomial the_poly;
scanf("%s", the_poly.name);

as well as

polynomial *addpoly(polynomial *a, polynomial *b)
{ /* adding code here */ }

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now