Solved

Naming Singly Linked List

Posted on 1997-10-10
1
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

707 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