Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem related to insertion a node in a linked list

Status
Not open for further replies.

agrawalyogesh

Programmer
Dec 6, 2001
3
IN
hello friends
i am making a linked list
when i create a node at the start a pointer address is allocated to it and afterwards when again i create a new node for appending in linked list the new node get the same address as already allocated to the prior node that is the start node
please help me out
 
it sounds like your "losing your head" (pun intended hehe). Can you post your create node code? and your structure/class for the node?

Matt
 
Dear Mr. Zyrenthian you have asked for the code of Create node and the structure of the node so they are as follows
also if you will give ur mail id i can able to mail your whole code then only you will be able to solve the problem
So the code for the creation of the node is as follows

The function is call as
append(&start,temp,a);
"start" is a new node
"temp" is a pointer character variable where the record is stored which has to be stored in the linked list

append(node **list,char *temp1,int x)
{
int i;
int flag=0;
node *n;
node *traverse;
char a[15]; * pointer to preceding key node */
traverse=*list;
if(*list==NULL)
{
*list= new node;
traverse=*list;
}

else
{
while(traverse->next!=NULL)
traverse=traverse->next;
traverse->next= new node;
traverse = traverse->next;
}
traverse->b = x;
for(i=0;i<30;i++)
{
traverse->name=temp1[i+1];
}
for(i=0;i<30;i++)
{
traverse->grpname=temp1[i+61];
}
flag=0;
for(i=0;i<15;i++)
{
a=temp1[i+291];
if (a=='-')
{
a=' ';
flag=1;
}
}
if(flag)
{
traverse->dopbal=amount(a);
traverse->copbal=0.0;
}
else
{
traverse->copbal=amount(a);
traverse->dopbal=0.0;
}
flag=0;
for(i=0;i<15;i++)
{
a=temp1[i+306];
if(a=='-')
{
a=' ';
flag=1;
}
}
if(flag)
{
traverse->dclosebal=amount(a);
traverse->cclosebal=0.0;
}
else
{
traverse->cclosebal=amount(a);
traverse->dopbal=0.0;
}
traverse->next=NULL;
return(0);
}


And the structure is as follows


struct ledger
{
int b;
char name[30];
char grpname[30];
float dopbal;
float dclosebal;
float copbal;
float cclosebal;
struct ledger *next;
};
typedef struct ledger node;
node *start;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top