copying and assigning Linked list

Hi everyone!

I again appeal for the help of the community. I have an assignment to assign 10 integers to a silgly linked list FROM A FILE! than I have to copy the singly linked list to a boubly linked list and reverse it.

My problems are: First I don't have Idea how to assign values from a file into the nodes of the linked list. should I first create an int array and to pass the content of the array into the linked list? Or there is any other way?

Second when I create functions for copying and reversing linked lists I pass there the list where I'm copying from DNodePtr copyToDoulby(NodePtr head) to copy it to the DNode the compiler gives me the mistake that "struct Node’ has no member named ‘DNodeData’" But it shouldn't occur because the function is of DNode type. Isnt it?

If anybody can give me a hint with these 2 problems i would be so grateful.

Thanks in advance for your time and suggestions
Radovan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 #include <iostream>
#include <fstream>
using namespace std;

struct Node{ // SINGLY LINKED LIST
  int data;
  Node *next;
};
typedef Node* NodePtr;

struct DNode{ //DOUBLY LINKED LIT
  int DNodeData;
  Node* next;
  Node* prev;
};
typedef Node *DNodePtr;

NodePtr addHeadNode(NodePtr head, int NewData); // ADDING INTO LIST
void printList(NodePtr head); //PRINTING LIST
DNodePtr copyToDoulby(NodePtr head); //COPYING SINGLY TO DOUBLY LIST
void reversePrintDoulby(DNodePtr dhead);// REVERSING DOUBLY LINKED LIST


int main(){

//HERE SUPPOSE TO BE SOMETHING WHICH ALLOWS ME TO ASSINGN VALUES FROM THE TEXT FILE INLO NODES OF THE SINGLY LIST.
  
  cout<< "SINGLY LINKED LIST: " << endl;
  
  void printList(NodePtr head); 
  
  cout<< endl << endl;
  
  
  cout<< "REVERSED DOUBLY LINKED LIST" << endl;
  
  void reversePrintDoulby(DNodePtr dhead);
  
 return 0; 
}

NodePtr addHeadNode(NodePtr head, int NewData){
  NodePtr NewPtr = new Node;
  
  NewPtr->data = NewData;
  NewPtr->next = head;
  
  return NewPtr;
}

void printList(NodePtr head){
  NodePtr p;
  p = head;
  
  while(p != NULL){
    cout<< p->data << endl;
    p=p->next;
  }
}

DNodePtr copyToDoulby(NodePtr head){
 
   NodePtr newPtr;
  newPtr->next -> head;//THE PROBLEM OCCURS HERE
  DNodePtr NewdPtr; //THE PROBLEM OCCURS HERE
  NewdPtr->next -> dhead; //THE PROBLEM OCCURS HERE
  
  while (newPtr != NULL){
    NewdPtr->DNodeData = newPtr->data; //THE PROBLEM OCCURS HERE
    NewdPtr = NewdPtr->next;
    newPtr = newPtr->next;
  }
  
}

void reversePrintDoulby(DNodePtr dhead){
   DNodePtr dlast;
   dlast = dhead;
   
   if (dlast->next != NULL){
     while(dlast->next != NULL){
      dlast = dlast->next;
      if (dlast->next == NULL){
	while(dlast->prev != NULL){//THE PROBLEM OCCURS HERE
	  cout<< dlast->DNodeData;
	  dlast = dlast->prev; //THE PROBLEM OCCURS HERE
	}
      }
     }
   }
   
   else{
     cout<< dlast->DNodeData;
   }
   
}
 




Topic archived. No new replies allowed.