SlideShare a Scribd company logo
1 of 12
Download to read offline
Please refer this solution. This is working file for Integers
Header file :-
-----------------------------------
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
struct node{
void * data;
node * next;
};
class LinkedList
{
private:
node* head ;
int size;
public:
LinkedList();
//method to create a node
node * create(void* data);
//method to append
void append(node * item);
//method to prepend
void prepend(node * item);
//insert in ascending order
void insertAscend(node * item);
//insert in ascending order
void insertDescend(node * item);
//display all nodes
void display();
//free the list
void freeUp();
};
#endif // LINKEDLIST_H
Source file :-
----------------------------------
#include "linkedlist.h"
#include
#include
#include
LinkedList::LinkedList()
{
//head = (node *)malloc(sizeof(node));
size = 0;
head = NULL;
}
//method to create a node
node * LinkedList::create(void* data){
node * newNode = (node *)malloc(sizeof(node));
newNode->data = malloc(sizeof(data));
memcpy(newNode->data,data,sizeof(data));
newNode->next = NULL;
return newNode;
}
//method to append
void LinkedList::append(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
while (current->next!=NULL )
{
current = current->next;
}
current->next = item ;
size++;
}
//method to prepend
void LinkedList::prepend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
item->next = head;
head = item;
size++;
}
//insert in ascending order
void LinkedList::insertAscend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
node * prev = NULL;
bool found = false;
while (current !=NULL){
int *current_data = static_cast(current->data);
int *item_data = static_cast(item->data);
if(*item_data < *current_data){
if(prev == NULL){
item->next = current;
if(current == head){
head = item;
}
}
else{
prev->next = item;
item->next = current;
}
found = true;
break;
}
prev = current;
current = current->next;
}
if(!found){
prev->next = item;
}
size++;
}
//insert in Descending order
void LinkedList::insertDescend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
node * prev = NULL;
bool found = false;
while (current !=NULL){
int *current_data = static_cast(current->data);
int *item_data = static_cast(item->data);
if(*item_data > *current_data){
if(prev == NULL){
item->next = current;
if(current == head){
head = item;
}
}
else{
prev->next = item;
item->next = current;
}
found = true;
break;
}
prev = current;
current = current->next;
}
if(!found){
prev->next = item;
}
size++;
}
//display all nodes
void LinkedList::display(){
int idx = 0;
node* current;
current = head;
while (current != NULL ){
idx++;
int *data = static_cast(current->data);
printf("data for item ::%dis :: %d ",idx,*data);
current = current->next;
}
}
//free the list
void LinkedList::freeUp(){
node* current;
current = head;
while (current->next!=NULL ){
head = current->next;
delete current;
current = head;
}
}
Main file :-
----------------------------
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
FILE *f;
f=fopen("/home/ramkumar/Study/Chegg/data.txt","r");
LinkedList list;
while(!feof(f)) {
int * data = (int*)malloc(sizeof(int));
fscanf(f,"%d ", data);
node* item = list.create(data);
list.insertDescend(item);
}
list.display();
list.freeUp();
return 0;
}
Solution
Please refer this solution. This is working file for Integers
Header file :-
-----------------------------------
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
struct node{
void * data;
node * next;
};
class LinkedList
{
private:
node* head ;
int size;
public:
LinkedList();
//method to create a node
node * create(void* data);
//method to append
void append(node * item);
//method to prepend
void prepend(node * item);
//insert in ascending order
void insertAscend(node * item);
//insert in ascending order
void insertDescend(node * item);
//display all nodes
void display();
//free the list
void freeUp();
};
#endif // LINKEDLIST_H
Source file :-
----------------------------------
#include "linkedlist.h"
#include
#include
#include
LinkedList::LinkedList()
{
//head = (node *)malloc(sizeof(node));
size = 0;
head = NULL;
}
//method to create a node
node * LinkedList::create(void* data){
node * newNode = (node *)malloc(sizeof(node));
newNode->data = malloc(sizeof(data));
memcpy(newNode->data,data,sizeof(data));
newNode->next = NULL;
return newNode;
}
//method to append
void LinkedList::append(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
while (current->next!=NULL )
{
current = current->next;
}
current->next = item ;
size++;
}
//method to prepend
void LinkedList::prepend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
item->next = head;
head = item;
size++;
}
//insert in ascending order
void LinkedList::insertAscend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
node * prev = NULL;
bool found = false;
while (current !=NULL){
int *current_data = static_cast(current->data);
int *item_data = static_cast(item->data);
if(*item_data < *current_data){
if(prev == NULL){
item->next = current;
if(current == head){
head = item;
}
}
else{
prev->next = item;
item->next = current;
}
found = true;
break;
}
prev = current;
current = current->next;
}
if(!found){
prev->next = item;
}
size++;
}
//insert in Descending order
void LinkedList::insertDescend(node * item){
if(head == NULL){
head = item;
size++;
return;
}
node* current;
current = head;
node * prev = NULL;
bool found = false;
while (current !=NULL){
int *current_data = static_cast(current->data);
int *item_data = static_cast(item->data);
if(*item_data > *current_data){
if(prev == NULL){
item->next = current;
if(current == head){
head = item;
}
}
else{
prev->next = item;
item->next = current;
}
found = true;
break;
}
prev = current;
current = current->next;
}
if(!found){
prev->next = item;
}
size++;
}
//display all nodes
void LinkedList::display(){
int idx = 0;
node* current;
current = head;
while (current != NULL ){
idx++;
int *data = static_cast(current->data);
printf("data for item ::%dis :: %d ",idx,*data);
current = current->next;
}
}
//free the list
void LinkedList::freeUp(){
node* current;
current = head;
while (current->next!=NULL ){
head = current->next;
delete current;
current = head;
}
}
Main file :-
----------------------------
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
FILE *f;
f=fopen("/home/ramkumar/Study/Chegg/data.txt","r");
LinkedList list;
while(!feof(f)) {
int * data = (int*)malloc(sizeof(int));
fscanf(f,"%d ", data);
node* item = list.create(data);
list.insertDescend(item);
}
list.display();
list.freeUp();
return 0;
}

More Related Content

Similar to Please refer this solution. This is working file for IntegersHeade.pdf

Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfalphaagenciesindia
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfhadpadrrajeshh
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfferoz544
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdfdeepakangel
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdfAKVIGFOEU
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdfshanki7
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdffootstatus
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfinfo335653
 

Similar to Please refer this solution. This is working file for IntegersHeade.pdf (20)

Linked lists
Linked listsLinked lists
Linked lists
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
 
fix the error - class Node{ int data- Node next-.pdf
fix the error -   class Node{           int data-           Node next-.pdffix the error -   class Node{           int data-           Node next-.pdf
fix the error - class Node{ int data- Node next-.pdf
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
How to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdfHow to delete one specific node in linked list in CThanksSolu.pdf
How to delete one specific node in linked list in CThanksSolu.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdf
 

More from sooryasalini

Polarity is measured on a scale of electronegativ.pdf
                     Polarity is measured on a scale of electronegativ.pdf                     Polarity is measured on a scale of electronegativ.pdf
Polarity is measured on a scale of electronegativ.pdfsooryasalini
 
Geometric isomers are a subset of stereoisomers. .pdf
                     Geometric isomers are a subset of stereoisomers. .pdf                     Geometric isomers are a subset of stereoisomers. .pdf
Geometric isomers are a subset of stereoisomers. .pdfsooryasalini
 
Scientists Contributions Stanley Miller Conducted an experiment .pdf
    Scientists Contributions   Stanley Miller Conducted an experiment .pdf    Scientists Contributions   Stanley Miller Conducted an experiment .pdf
Scientists Contributions Stanley Miller Conducted an experiment .pdfsooryasalini
 
1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdfsooryasalini
 
The components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfThe components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfsooryasalini
 
-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdfsooryasalini
 
NO+ note O has one more electron then N, thus, .pdf
                     NO+  note O has one more electron then N, thus, .pdf                     NO+  note O has one more electron then N, thus, .pdf
NO+ note O has one more electron then N, thus, .pdfsooryasalini
 
Yes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfYes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfsooryasalini
 
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfWHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfsooryasalini
 
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfWeb 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfsooryasalini
 
There are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfThere are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfsooryasalini
 
now a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfnow a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfsooryasalini
 
5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdfsooryasalini
 
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdfpH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdfsooryasalini
 
Solution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfSolution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfsooryasalini
 
Solution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfSolution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfsooryasalini
 
S and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfS and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfsooryasalini
 
Simple DefinationsIntertidal zone is the area that is above wate.pdf
Simple DefinationsIntertidal zone  is the area that is above wate.pdfSimple DefinationsIntertidal zone  is the area that is above wate.pdf
Simple DefinationsIntertidal zone is the area that is above wate.pdfsooryasalini
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfsooryasalini
 
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdf
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdfProteobacteria are major phylum of gram negative bacteria. Major gro.pdf
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdfsooryasalini
 

More from sooryasalini (20)

Polarity is measured on a scale of electronegativ.pdf
                     Polarity is measured on a scale of electronegativ.pdf                     Polarity is measured on a scale of electronegativ.pdf
Polarity is measured on a scale of electronegativ.pdf
 
Geometric isomers are a subset of stereoisomers. .pdf
                     Geometric isomers are a subset of stereoisomers. .pdf                     Geometric isomers are a subset of stereoisomers. .pdf
Geometric isomers are a subset of stereoisomers. .pdf
 
Scientists Contributions Stanley Miller Conducted an experiment .pdf
    Scientists Contributions   Stanley Miller Conducted an experiment .pdf    Scientists Contributions   Stanley Miller Conducted an experiment .pdf
Scientists Contributions Stanley Miller Conducted an experiment .pdf
 
1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf1) Microfinance is the provision of small-scale financial services t.pdf
1) Microfinance is the provision of small-scale financial services t.pdf
 
The components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdfThe components of individual health are as followsThe three compon.pdf
The components of individual health are as followsThe three compon.pdf
 
-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf-Lower income households have become more concentrated in U.S. centr.pdf
-Lower income households have become more concentrated in U.S. centr.pdf
 
NO+ note O has one more electron then N, thus, .pdf
                     NO+  note O has one more electron then N, thus, .pdf                     NO+  note O has one more electron then N, thus, .pdf
NO+ note O has one more electron then N, thus, .pdf
 
Yes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdfYes, we should be very suspicious of the bones authenticity. This .pdf
Yes, we should be very suspicious of the bones authenticity. This .pdf
 
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdfWHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
WHITE COLLAR CRIMEWhite-collar crime is nonviolent crime commited.pdf
 
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdfWeb 3.0 is just how, why and at what time.Web serviceis a software.pdf
Web 3.0 is just how, why and at what time.Web serviceis a software.pdf
 
There are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdfThere are a few different reagent could be used to perform this tran.pdf
There are a few different reagent could be used to perform this tran.pdf
 
now a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdfnow a days security is very important to organization and physical s.pdf
now a days security is very important to organization and physical s.pdf
 
5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf5.Write the VHDL code for the state machine.library ieee;use i.pdf
5.Write the VHDL code for the state machine.library ieee;use i.pdf
 
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdfpH = pKa + log([A-][HA])(base) HONH2 + H2O  (acid) HONH3+ + OH-.pdf
pH = pKa + log([A-][HA])(base) HONH2 + H2O (acid) HONH3+ + OH-.pdf
 
Solution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdfSolution Relation between carpels and locules Carpels is the p.pdf
Solution Relation between carpels and locules Carpels is the p.pdf
 
Solution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdfSolution.Providing legal advice to the president of the company co.pdf
Solution.Providing legal advice to the president of the company co.pdf
 
S and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdfS and Se are 6th group elementsSize increase the leaving nature in.pdf
S and Se are 6th group elementsSize increase the leaving nature in.pdf
 
Simple DefinationsIntertidal zone is the area that is above wate.pdf
Simple DefinationsIntertidal zone  is the area that is above wate.pdfSimple DefinationsIntertidal zone  is the area that is above wate.pdf
Simple DefinationsIntertidal zone is the area that is above wate.pdf
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdf
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdfProteobacteria are major phylum of gram negative bacteria. Major gro.pdf
Proteobacteria are major phylum of gram negative bacteria. Major gro.pdf
 

Recently uploaded

Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 

Recently uploaded (20)

Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 

Please refer this solution. This is working file for IntegersHeade.pdf

  • 1. Please refer this solution. This is working file for Integers Header file :- ----------------------------------- #ifndef LINKEDLIST_H #define LINKEDLIST_H struct node{ void * data; node * next; }; class LinkedList { private: node* head ; int size; public: LinkedList(); //method to create a node node * create(void* data); //method to append void append(node * item); //method to prepend void prepend(node * item); //insert in ascending order void insertAscend(node * item); //insert in ascending order void insertDescend(node * item); //display all nodes void display(); //free the list void freeUp(); }; #endif // LINKEDLIST_H Source file :- ----------------------------------
  • 2. #include "linkedlist.h" #include #include #include LinkedList::LinkedList() { //head = (node *)malloc(sizeof(node)); size = 0; head = NULL; } //method to create a node node * LinkedList::create(void* data){ node * newNode = (node *)malloc(sizeof(node)); newNode->data = malloc(sizeof(data)); memcpy(newNode->data,data,sizeof(data)); newNode->next = NULL; return newNode; } //method to append void LinkedList::append(node * item){ if(head == NULL){ head = item; size++; return; } node* current; current = head; while (current->next!=NULL ) { current = current->next; } current->next = item ; size++; } //method to prepend void LinkedList::prepend(node * item){
  • 3. if(head == NULL){ head = item; size++; return; } item->next = head; head = item; size++; } //insert in ascending order void LinkedList::insertAscend(node * item){ if(head == NULL){ head = item; size++; return; } node* current; current = head; node * prev = NULL; bool found = false; while (current !=NULL){ int *current_data = static_cast(current->data); int *item_data = static_cast(item->data); if(*item_data < *current_data){ if(prev == NULL){ item->next = current; if(current == head){ head = item; } } else{ prev->next = item; item->next = current; } found = true; break;
  • 4. } prev = current; current = current->next; } if(!found){ prev->next = item; } size++; } //insert in Descending order void LinkedList::insertDescend(node * item){ if(head == NULL){ head = item; size++; return; } node* current; current = head; node * prev = NULL; bool found = false; while (current !=NULL){ int *current_data = static_cast(current->data); int *item_data = static_cast(item->data); if(*item_data > *current_data){ if(prev == NULL){ item->next = current; if(current == head){ head = item; } } else{ prev->next = item; item->next = current; } found = true;
  • 5. break; } prev = current; current = current->next; } if(!found){ prev->next = item; } size++; } //display all nodes void LinkedList::display(){ int idx = 0; node* current; current = head; while (current != NULL ){ idx++; int *data = static_cast(current->data); printf("data for item ::%dis :: %d ",idx,*data); current = current->next; } } //free the list void LinkedList::freeUp(){ node* current; current = head; while (current->next!=NULL ){ head = current->next; delete current; current = head; } } Main file :- ----------------------------
  • 6. #include #include using namespace std; int main(int argc, char *argv[]) { FILE *f; f=fopen("/home/ramkumar/Study/Chegg/data.txt","r"); LinkedList list; while(!feof(f)) { int * data = (int*)malloc(sizeof(int)); fscanf(f,"%d ", data); node* item = list.create(data); list.insertDescend(item); } list.display(); list.freeUp(); return 0; } Solution Please refer this solution. This is working file for Integers Header file :- ----------------------------------- #ifndef LINKEDLIST_H #define LINKEDLIST_H struct node{ void * data; node * next; }; class LinkedList { private: node* head ; int size; public:
  • 7. LinkedList(); //method to create a node node * create(void* data); //method to append void append(node * item); //method to prepend void prepend(node * item); //insert in ascending order void insertAscend(node * item); //insert in ascending order void insertDescend(node * item); //display all nodes void display(); //free the list void freeUp(); }; #endif // LINKEDLIST_H Source file :- ---------------------------------- #include "linkedlist.h" #include #include #include LinkedList::LinkedList() { //head = (node *)malloc(sizeof(node)); size = 0; head = NULL; } //method to create a node node * LinkedList::create(void* data){ node * newNode = (node *)malloc(sizeof(node)); newNode->data = malloc(sizeof(data)); memcpy(newNode->data,data,sizeof(data)); newNode->next = NULL;
  • 8. return newNode; } //method to append void LinkedList::append(node * item){ if(head == NULL){ head = item; size++; return; } node* current; current = head; while (current->next!=NULL ) { current = current->next; } current->next = item ; size++; } //method to prepend void LinkedList::prepend(node * item){ if(head == NULL){ head = item; size++; return; } item->next = head; head = item; size++; } //insert in ascending order void LinkedList::insertAscend(node * item){ if(head == NULL){ head = item; size++; return; }
  • 9. node* current; current = head; node * prev = NULL; bool found = false; while (current !=NULL){ int *current_data = static_cast(current->data); int *item_data = static_cast(item->data); if(*item_data < *current_data){ if(prev == NULL){ item->next = current; if(current == head){ head = item; } } else{ prev->next = item; item->next = current; } found = true; break; } prev = current; current = current->next; } if(!found){ prev->next = item; } size++; } //insert in Descending order void LinkedList::insertDescend(node * item){ if(head == NULL){ head = item; size++; return;
  • 10. } node* current; current = head; node * prev = NULL; bool found = false; while (current !=NULL){ int *current_data = static_cast(current->data); int *item_data = static_cast(item->data); if(*item_data > *current_data){ if(prev == NULL){ item->next = current; if(current == head){ head = item; } } else{ prev->next = item; item->next = current; } found = true; break; } prev = current; current = current->next; } if(!found){ prev->next = item; } size++; } //display all nodes void LinkedList::display(){ int idx = 0; node* current; current = head;
  • 11. while (current != NULL ){ idx++; int *data = static_cast(current->data); printf("data for item ::%dis :: %d ",idx,*data); current = current->next; } } //free the list void LinkedList::freeUp(){ node* current; current = head; while (current->next!=NULL ){ head = current->next; delete current; current = head; } } Main file :- ---------------------------- #include #include using namespace std; int main(int argc, char *argv[]) { FILE *f; f=fopen("/home/ramkumar/Study/Chegg/data.txt","r"); LinkedList list; while(!feof(f)) { int * data = (int*)malloc(sizeof(int)); fscanf(f,"%d ", data); node* item = list.create(data); list.insertDescend(item); } list.display(); list.freeUp();