Solved

Naming Singly Linked List

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

821 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