Albar_237739.docx - Task 1#include <iostream> using namespace std class Node/Define a class Node public int exp int coff Node next Node Node(int,int

Albar_237739.docx - Task 1#include <iostream> using...

This preview shows page 1 - 3 out of 5 pages.

Task # 1 #include <iostream> using namespace std; class Node //Define a class Node { public: int exp; int coff; Node* next; Node(); Node(int,int); }; Node::Node() //Constructure of Node { exp=0; coff=0; next=NULL; } Node::Node(int x,int y) //Overloading constructor of Node by passing integer values { exp = x; coff = y; next=NULL; } class LinkedList //Define class Linkedlist { public: Node* head; LinkedList(); //Define constructure of LinkedList void AppendtoList(int,int); //Define function that adds nodes to the link list void displayListElements(); //Define function that displays elements }; LinkedList::LinkedList() //Constructor of Linkedlist { head= NULL; //Set head to null } void LinkedList::AppendtoList(int x,int y) { Node* tempNode = new Node; //Allocates dynamic memory to a temperory Node //Assigns the passed values of coefficient and exponential to the temporary Node tempNode->exp=x; tempNode->coff=y; if (head==NULL) { head=tempNode; } else { Node* temppointer = head; while(temppointer->next!= NULL) //Find the end of linklist
Image of page 1

Subscribe to view the full document.

{ temppointer=temppointer->next; } temppointer->next=tempNode; //Point to the location of the temporary Node } } void LinkedList::displayListElements() //Print elements in the linkedlist
Image of page 2
Image of page 3
  • Fall '19
  • Sir. Kashaf

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes