i need to create a linked lists in size =N
each struct pointing to the next sruct the user will enter and the first struct pointed by constant pointer head.
TNX ............. - #include <stdio.h>
-
#define size=5
-
void main()
-
-
{
-
typedef struct
-
{
-
int x,y;
-
struct Strct *next;
-
}Coordinate;
-
-
for(i=0; i<size; i++)
-
{
-
-
Coordinate (?????);
-
printf("Enter name & value: <name,value>\n");
-
scanf("%d,%d",(????));
-
}
-
-
-
-
}
19 3516
And what is your question?
kind regards,
Jos
how to do it , what i should add to the code ?
tnx....
Each node in a linked list consists of two parts: there are the links used to connect the nodes together; and there is the body or payload of the node. What goes in the body of your list?
Please tell me a little of what you've already learned about linked lists?
If you go through books you will get functions to add some data to list. Just go through any book, try to understand, post again if you still come across any doubts.
Thanks,
Manjunath
do you want help on how to learn how to create a linked list or are you trying to get it built for you?
@loonman
yes , i want to learn all bout linked lists , i do read books .
__________________________________________________ ________________
ok.... , what about that ? - #include <stdio.h>
-
-
typedef struct
-
{
-
int x,y;
-
char str[20];
-
struct Node* next;
-
}Node ;
-
-
// i will add option to user initialize the field latter (thats not what important)
-
void main()
-
{
-
Node *head=NULL, *temp ;
-
int i, size;
-
printf("Enter the size of linked list\n");
-
scanf("%d",&size);
-
-
for(i=0; i<size; i++)
-
{
-
temp=(Node*)malloc(sizeof(Node));
-
temp->next=head;
-
head=temp;
-
}
-
-
}
-
the warning mesages:
line 21 : warning C4133: '=' : incompatible types - from 'Node *' to 'Node *
line 20 : warning C4013: 'malloc' undefined; assuming extern returning int
tnx..
Hi,
For first warning -- you have to define structure like below,
struct node
{
int x,y;
char str[20];
struct node *next;
};
typedef struct node Node;
For second warning -- malloc is defined in stdlib.h header file, so you have to include that header file.
Thanks,
Manjunath
@sedaw @manjuks
In your original code the first place the type name "Node" appears is in the definition of the "next" field. The compiler does not yet recognize that name as a type. Now look at Manjunath's alternative -- the compiler is aware there is a struct named "node" by the time it gets to the definition of the "next" field. That's why Manjunath's code makes the compiler warning go away.
Divide and conquer.
You need a function that allocates a node and initializes its payload. Then you need another function that inserts a node into a linked list.
Does the assignment say whether you're to create a singly- or doubly-linked list?
thank you all ! @donbock
what`s the difference of singly- or doubly-linked ?
that`s not assignment i just tryin to learn linked lists .
TNX .
@sedaw
Linked lists are described in any number of software engineering books.
The internet is your friend: there's Wikipedia; a link provided in an earlier forum reply; and there's Google.
This forum is pretty good at answering specific questions. An open-ended question like "tell me about linked lists" is best answered by an essay or book chapter, not a forum reply that I throw together in a couple of minutes.
@sedaw
A singly linked list contains one pointer per node that points to another node; e.g.
A ---> B ---> C ---> D ---> E
this list contains five elements where node A points to node B and at the end node D points to node E which is the last node in the list (A is the first node). The pointer of node E doesn't point to another node and is null.
A doubly linked list has two pointers per node; one pointer points to a next node (same as a singly linked list) and the other pointer points to the previous nodes in the list: e.g.
A <==> B <==> C <==> D <==> E
The last node (E) doesn't pont to a next node and the first node (A) doesn't point to a previous node. There are variations on the scenario.
kind regards,
Jos
tnx...
one more litlle thing.
what`s wrong in line 24:
scanf("%d,%d",head->x,head->y);
theres no debugging prob .
but the prog collapse in line 24 . - #include <stdio.h>
-
#include <stdlib.h>
-
-
struct node
-
{
-
int x,y;
-
char str[20];
-
struct Node* next;
-
} ;
-
typedef struct node Node;
-
-
void main()
-
{
-
Node *head=NULL, *temp, *currItem;
-
int i,size;
-
printf("Enter the size of linked list\n");
-
scanf("%d",&size);
-
for(i=0; i<size; i++)
-
{
-
temp=(Node*)malloc(sizeof(Node));
-
temp->next=head;
-
head=temp;
-
printf("Enter coordinate, <x,y>\n");
-
scanf("%d,%d",head->x,head->y);
-
}
-
currItem=head;
-
for(i=0; i<size; i++)
-
{
-
printf("value of cuurent item on linked list: %d\n",currItem->x);
-
currItem=currItem->next;
-
}
-
-
}
-
@sedaw
The scanf function needs to know where it has to store its parsed result; you have to pass it the address of something to tell that to the scanf function. You are passsing it two ints instead which are not addresses. Do this instead: -
scanf("%d,%d",&(head->x),&(head->y));
-
Here you are passing the addresses of those two int slots so scanf knows where to put its results.
kind regards,
Jos
ps. don't forget to type a comma between those two ints; scanf wants to see it according to your format string "%d,%d"
@sedaw
malloc will return NULL if it is unable to allocate the memory you request. You should always check the return value. If malloc returns NULL then you could [for example] print a message to stderr and invoke exit(1).
... and it's "int main( ... )", not "void main( ... )"; when will you people learn? It even saves one entire keystroke, whick makes millions of keystrokes per year so your keyboard doesn't wear out that much so you save money, reduce your debts and buy your dog a proper meal and more important: it's the Standard! When will you learn instead of act monkey-see-monkey-do with that stupid Microsoft, the source of this silly error!
kind regards,
Jos ;-)
amen brother!!! heathens! int your main! avoid the void!!
@loonman
I know that the OP has sinned father; may I suggest a short and efficient defenestration and afterwards we'll wiggle our genitals towards his general direction so his remains will be in shame on the pavement.
kind regards,
Jos ;-)
@JosAH
the imagery is so vivid. i totally agree. (wiping tears from my eyes)
in complete admiration,
Loon
Sign in to post your reply or Sign up for a free account.
Similar topics
by: surrealtrauma |
last post by:
I want to ask what's the differences between doubly liked list and linear
liked list, and also the circular doubly liked list in terms of
implementation. THX
|
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...
|
by: Chris Powell |
last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows
each) that I wish to create linked tables in Access rather than
importing into Access. The two source Excel files change...
|
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...
|
by: sandeep |
last post by:
When we use STL which memory space it will use whither it is stack or
heap or data segment
How to make STL to create in heap?
How to make whole container to create in heap?
I think container...
|
by: Dongsheng Ruan |
last post by:
with a cell class like this:
#!/usr/bin/python
import sys
class Cell:
def __init__( self, data, next=None ):
self.data = data
|
by: yaarnick |
last post by:
Create a linked list data structure library to hold strings. Then library should support the following linked list operations.
Create() – Creates the linked list
Insert() – Insert a string into the...
|
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...
|
by: The Natural Philosopher |
last post by:
I am trying to create what amounts to an array of 'structures'.
I.e. I want to dynamically add to and access an object as
myobject.anothernumber // actually represents a nesting level.
and
...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |