Question

c++ on MS VS it gives an error that on line 33 uninitialized local variable used(...

c++ on MS VS it gives an error that on line 33 uninitialized local variable used( or see comment in code). On other compilers, code runs fine.

=====================================

#include <iostream>

using namespace std;

// Node structure w/ power and coefficient
struct Node
{
   int coeff;
   int pow;
   struct Node *next;
};

void create(int x, int y, struct Node** temp) {

   //declare structs
   struct Node *a, *b;

   //temp
   b = *temp;
   //if b null
   if (b == NULL) {
       a = new Node;
       a->coeff = x;
       a->pow = y;
       *temp = a;
       a->next = new Node;
       a = a->next;
       a->next = NULL;
   }

   //same as above, but do not allalocate new space first
   else {
       a->coeff = x;//<-------------------------this line that give error.
       a->pow = y;
       a->next = new Node;
       a = a->next;
       a->next = NULL;
   }
}

  

      

       int main()
       {
          

           return 0;


       }

Homework Answers

Answer #1
#include <iostream>

using namespace std;

// Node structure w/ power and coefficient
struct Node {
    int coeff;
    int pow;
    struct Node *next;
};

void create(int x, int y, struct Node **temp) {

    //declare structs
    struct Node *a, *b;

    //temp
    b = *temp;
    //if b null
    if (b == NULL) {
        a = new Node;
        a->coeff = x;
        a->pow = y;
        *temp = a;
        a->next = new Node;
        a = a->next;
        a->next = NULL;
    }
        //same as above, but do not allalocate new space first
    else {
        a = new Node;   // we need to create a new node before assigning it values..
        a->coeff = x;//<-------------------------this line that give error.
        a->pow = y;
        a->next = new Node;
        a = a->next;
        a->next = NULL;
    }
}


int main() {
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
i want to complete this code to insert a new node in the middle of list...
i want to complete this code to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node). this is the code #include <iostream> #include <stdlib.h> using namespace std ; struct Node{                int data;                Node *link ;}; struct Node *head=NULL, *tail=NULL; /* pointers to Node*/ void InsertFront(); void InsertRear(); void DeleteFront(); void DeleteRear(); int main(){                int choice;                do{                               cout << "1:...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
IN C++ PLEASE!!! What needs to be done is in the code itself where it is...
IN C++ PLEASE!!! What needs to be done is in the code itself where it is written TO DO List! #include<iostream> using namespace std; template<typename T> class DoubleList{​​​​​     class Node{​​​​​     public: T value; Node* next; Node* prev;         Node(T value = T(), Node* next = nullptr, Node* prev = nullptr){​​​​​             this->value = value;             this->next = next;             this->next = next;         }​​​​​     }​​​​​;     int size;     Node* head;     Node* tail; public:     DoubleList(){​​​​​         size = 0;         head = nullptr;     }​​​​​     int length(){​​​​​         return size;     }​​​​​...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class is empty. Complete the destructor so the memory allocated for each node in the BST is freed. Make a couple of different trees in your main method or in a function to test the destructor (the program should not crash upon exiting). bst.zip (includes the following files below in c++): bst.h: #pragma once #include #include "node.cpp" using namespace std; template class BST { public:...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>    #include <cstdlib> #include "QueueADT.h" using namespace std; // Definition of the node template <class ItemType> struct NodeType {        ItemType info;        NodeType<ItemType> *next; }; template <class ItemType> class LinkedQueueType: public QueueADT<ItemType> { public:        // Constructor        LinkedQueueType();           // Default constructor.           // Post: An empty queue has been created. queueFront = NULL;           //       queueBack = NULL;...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
Trying to pass a pointer through the function bool CustomerList::updateStore() that will allow me to modify...
Trying to pass a pointer through the function bool CustomerList::updateStore() that will allow me to modify an input. Ex. (1234, "Name", "Street Address", "City", "State", "Zip") Using the function bool CustomerList::updateStore() Updating..successful New Address: (0001, "Store", "111 Main St.", "Townsville", "GA", "67893") CustomerList.h #pragma once; #include #include "Store.h" class CustomerList {    public:        Store *m_pHead;        CustomerList();        ~CustomerList();        bool addStore(Store *s);        Store *removeStore(int ID);        Store *getStore(int ID);       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT