943,725 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 331
  • C++ RSS
Nov 14th, 2008
0

help me plz

Expand Post »
ok .guys .i m sorry for my previous msg.Can anybody tell me how i can take user 's value,then divided into 8 groups and then i have to make node for that 8 values.Here is my code


#include<stdio.h>

struct node
{
	long int data;
	struct node* llink;
	struct node* rlink;

	node()
	{
		data=0;
		llink = NULL;
		rlink = NULL;
	}

};


struct head
{

	int noofdigit;
	char sign;
	struct node* left;
	struct node* right;


	head()
	{
		noofdigit = 0;
		sign =0;
		left = NULL;
		right =NULL;
	}

};

char Sign(struct head* headpointer)
{
	return headpointer->sign;
}



struct node* FirstLeft(struct head* headpointer)
{
	return headpointer ->left;
}

struct node* FirstRight(struct head* headpointer)
{
	return headpointer ->right;
}


struct node* NextLeft(struct node* nodetosearch)
{
		return nodetosearch ->rlink;
}

void InsertLeft(struct head* headnode,struct node* nodetoinsert)
{

	if(FirstLeft(headnode) ==NULL || FirstRight(headnode) == NULL)
	{
		headnode ->left = nodetoinsert;
		headnode ->right = nodetoinsert;
	}

	else

	{
		headnode ->left->llink = nodetoinsert;
		nodetoinsert->rlink = FirstLeft(headnode);
		headnode->left = nodetoinsert;
	}
}


int over_flow(struct node* nodetochk)
{
	long int ovrflwdgt = 0;

	ovrflwdgt = nodetochk->data / 100000000;
	if(ovrflwdgt !=0)
	{

			nodetochk->data = nodetochk->data - (ovrflwdgt* 100000000);
	}
	return ovrflwdgt;
}



	

void Add(struct head* oprnd1,struct head* oprnd2,struct head* result)
{


	struct node* n1,*n2 , *rslt;
	long int sum,ovrflwdgt = 0;

	if(Sign(oprnd1) == Sign(oprnd2))
	{

		n1 = FirstRight(oprnd1);
		n2 = FirstRight(oprnd2);

		while(n1!=NULL && n2!=NULL)
		{

			sum = n1->data + n2->data + ovrflwdgt;
			rslt = new struct node;
			rslt->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n1 = NextLeft(n1);
			n2 = NextLeft(n2);
		}

		while(n1 != NULL)
		{

			sum = n1->data + ovrflwdgt;
			rslt = new struct node;
			rslt->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n1 = NextLeft(n1);
			n2 = NextLeft(n2);
		}

		while(n2 != NULL)
		{
			sum = n2->data + ovrflwdgt;
			rslt = new struct node;
			rslt ->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n2 = NextLeft(n2);
		}

		if(ovrflwdgt > 0)
		{

			rslt = new struct node;
			rslt->data = ovrflwdgt;
			InsertLeft(result,rslt);
		}

	}

}
#include<stdio.h>

struct node
{
	long int data;
	struct node* llink;
	struct node* rlink;

	node()
	{
		data=0;
		llink = NULL;
		rlink = NULL;
	}

};


struct head
{

	int noofdigit;
	char sign;
	struct node* left;
	struct node* right;


	head()
	{
		noofdigit = 0;
		sign =0;
		left = NULL;
		right =NULL;
	}

};

char Sign(struct head* headpointer)
{
	return headpointer->sign;
}



struct node* FirstLeft(struct head* headpointer)
{
	return headpointer ->left;
}

struct node* FirstRight(struct head* headpointer)
{
	return headpointer ->right;
}


struct node* NextLeft(struct node* nodetosearch)
{
		return nodetosearch ->rlink;
}

void InsertLeft(struct head* headnode,struct node* nodetoinsert)
{

	if(FirstLeft(headnode) ==NULL || FirstRight(headnode) == NULL)
	{
		headnode ->left = nodetoinsert;
		headnode ->right = nodetoinsert;
	}

	else

	{
		headnode ->left->llink = nodetoinsert;
		nodetoinsert->rlink = FirstLeft(headnode);
		headnode->left = nodetoinsert;
	}
}


int over_flow(struct node* nodetochk)
{
	long int ovrflwdgt = 0;

	ovrflwdgt = nodetochk->data / 100000000;
	if(ovrflwdgt !=0)
	{

			nodetochk->data = nodetochk->data - (ovrflwdgt* 100000000);
	}
	return ovrflwdgt;
}



	

void Add(struct head* oprnd1,struct head* oprnd2,struct head* result)
{


	struct node* n1,*n2 , *rslt;
	long int sum,ovrflwdgt = 0;

	if(Sign(oprnd1) == Sign(oprnd2))
	{

		n1 = FirstRight(oprnd1);
		n2 = FirstRight(oprnd2);

		while(n1!=NULL && n2!=NULL)
		{

			sum = n1->data + n2->data + ovrflwdgt;
			rslt = new struct node;
			rslt->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n1 = NextLeft(n1);
			n2 = NextLeft(n2);
		}

		while(n1 != NULL)
		{

			sum = n1->data + ovrflwdgt;
			rslt = new struct node;
			rslt->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n1 = NextLeft(n1);
			n2 = NextLeft(n2);
		}

		while(n2 != NULL)
		{
			sum = n2->data + ovrflwdgt;
			rslt = new struct node;
			rslt ->data = sum;
			InsertLeft(result,rslt);
			ovrflwdgt = over_flow(rslt);
			n2 = NextLeft(n2);
		}

		if(ovrflwdgt > 0)
		{

			rslt = new struct node;
			rslt->data = ovrflwdgt;
			InsertLeft(result,rslt);
		}

	}
}
Similar Threads
Reputation Points: 7
Solved Threads: 0
Newbie Poster
laki234 is offline Offline
10 posts
since Nov 2008
Nov 14th, 2008
0

Re: help me plz

lol...you wan't people to go through all that code and find what your having problems with? I think you should be more specific as to what the problems are, and maybe post a more relevant piece of the code.
Reputation Points: 352
Solved Threads: 109
Master Poster
skatamatic is offline Offline
775 posts
since Nov 2007
Nov 14th, 2008
0

Re: help me plz

Do you have the code pasted twice?

If it's your code, then shouldn't you know how to to add data to your nodes?
And divide by eight groups? Like eight lines of input, or eight values in a single line?
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Class with other classes, newbie
Next Thread in C++ Forum Timeline: proxy local





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC