Solved

Naming Singly Linked List

Posted on 1997-10-10
1
177 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

792 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