Explore BrainMass
Share

Add Function for Long Integer Linked List

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Long interger linked list add function

Posting I am working on program assignment in structures (c language)after entering the required intergers the add function will not compile.I receive error messages I am using a Microsoft c, c++ 6.0 compiler. The help required is to provide a working add function in c. Hopefully after that I will be be able to write similar functions to subtract multiply and divide.

The given problem requires that an add function be provided that should add two given lists n and m.

The source code of the problem is attached

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
int data; // char field data
struct node* next; //pointer field next
}NODE,*NODEP,**NODEPP; //defines three common types

// Function prototypes

void addhead(NODEPP listp,int value);

void getinput1( NODEPP );

void getinput2( NODEPP );
void showtext ( char* );
void showlist( char*,NODEP);
void add_list( listp );
void add();
void subtract();
void multiply();
void divide();
void main (void)
{

char cmd;

showtext(" Enter a to add, s to subtract, m to multiply , d to divide,q when finished");
for (;;)
{
scanf("%c",&cmd);

switch(cmd)
{
case 'a': add(); //addition

break;
case 's': subtract(); // subtract
break;
case 'm':multiply(); //multiply
break;
case 'd':divide(); //divide
break;
case 'q':
exit(0);
break;
}
showtext("nEND OF RUNn");
}

}// end of main

// Adds new node at the heaad of the list. puts value in the data field

void addhead(NODEPP listp, int value)
{

NODEP p = (NODEP)malloc( sizeof (NODE));
p->data = value; // Data Field gets value
p->next = *listp; // links p node to old head
*listp = p; // makes p a new head node
}

void getinput1( NODEPP listp ) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int n;

printf("Enter a series of integers (! when finished ):");

while((scanf("%d",&n))==1)

addhead(listp,n); //Add new node to list

}

void getinput2( NODEPP listp) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int m;

printf("Enter a second series of integers (! when finished ):");

while((scanf("%d",&m))==1)

addhead(listp,m); //Add new node to list

}

void showtext ( char* string ) //Displays text
{

printf(string);

}

void showlist(char* string, NODEP list) // Prints list to screen
{

int i =1;
showtext(string);
while (list !=NULL)
{
printf( "%5d",list->data);
if(i++% 10 ==0)showtext("n");
list =list->next;
}
showtext("n END OF LISTn");

}

void add(NODEPP listp ) //add function
{
NODEP n= NULL;
NODEP m =NULL;
NODEP t= NULL;

int tPtr;
tPtr=&t;
showtext( "**INITIAL LIST DATA**n");

getinput1( &n);
showlist("List 1n",n);
getchar();

getinput2( &m);
showlist("List 2n",m);

getchar();

while(t!=0)
{
t->data= n->data+m->data;
}

showlist( "The sum of List 1 and List 2 is:n",t);
}
void subtract(NODEPP listp)

{

}

void multiply()
{

}

void divide()
{

}

© BrainMass Inc. brainmass.com October 16, 2018, 4:01 pm ad1c9bdddf
https://brainmass.com/computer-science/linked-lists/add-function-long-integer-linked-list-11207

Attachments

Solution Preview

The given problem requires that an add function be provided that should add two given lists n and m. Please verify that the following steps are done in order to achieve the desired result.

1. getinput1() is used to create the linked list of the first series of integers n.
2. getinput2() is used to create the linked list of the second series of integers m.
3. for each node (i.e each integer) of the first linked list n, create a new node of another list t, such that t->data = n->data + ...

Solution Summary

The given problem requires that an add function be provided that should add two given lists n and m. Also use it to subtract, multiply and divide, exactly the same way, only in division check that you do not divide by zero.

$2.19
Similar Posting

What is the connection between long-term anxiety and social incompetence?

The article attached: (Burt Obradovic) is the article I need help with and will be coupled with another article (see hyperlink: Twenge) that is on how and why anxiety has increased in children and adults over the years. I will leave the hyperlink to the Twenge article in case it is needed.
http://www.apa.org/pubs/journals/features/psp-7961007.pdf
I have already addressed the Twenge article; just need help with the attached Burt Obradovic article.

The topic of the final paper, overall, is about how exposure to high levels of anxiety causes a future conditioned emotional response such as social incompetence.

Need help with:

Respond to the following questions for the article:

a. Use APA format

b. Summarize article. For the article it is helpful to respond to the following questions:
i. what (was done)
ii. target population of the research - who were they discussing
iii. how (was it done)
iv. what were the findings
v. contributions/recommendations that may have been made regarding the findings

c. Worth of article? Findings (was it an article that helped support the
selected topic area? Was it well written? Did it reveal new ideas, findings, etc., regarding the topic article?).

d. What was found overall (general statements of the findings). Be inclusive.

e. Knowledge, skills, insights overall that were gained.

View Full Posting Details