Need urgent help with this

so i posted this a little while back:
Write a C++ program that implements a linked list as an abstract data type.
The program must:
 Be type flexible, that is, could be a list of integers, string, or any type.
 allow the user to add members into the list
 delete members from the list
 make sure the list is still sorted after all the deletion and addition
Show all the function implementation.

here is my code:
#include <iostream>

using namespace std;

typedef struct list_node{
int data;
deque<int> intList;struct list_node*next;
}
node;
node*getNewNode(int data){
node *new_node=new node;
new_node->data = data;
new_node->next = NULL;
return new_node;
}

void displayList(node*head){
cout <<"List is been displayed: ";
while(head !=NULL){
cout << head->data<<"->";
head=head->next;
}
cout <<"NULL " << endl;
}
node *insertNodeBeg(node *head, int data){

node* ptr = getNewNode(data);
if(head == NULL){
head=ptr;
}
else{
ptr->next = head;
head=ptr;
}
return head;
}
node *insertNodeEnd(node *head, int data){
node* ptr = getNewNode(data);
if(head == NULL){
head=ptr;
}
else{
node * temp=head;
while(temp->next != NULL){
temp= temp->next;
}
temp->next=ptr;
}
return head;
}

node *insertNodeAfter(node *head, int element,int data){
node *temp = searchNode(head ,element);
if(temp == NULL){
cout<< "Element not found!"<<endl;
}
else{
node*ptr= getNewNode(data);
if(temp->next==NULL){
temp->next =ptr;
}
else{
ptr->next=temp->next;
tmep->next=ptr;
}
}
return head;
}

node *deleteNode(node *head , int element){
node *temp = searchNode(head ,element);
if(temp == NULL){
cout<< "Node to be deleted not found!"<<endl;
}
else{
if(temp == head){
head=head->next;
delete temp;
}
else{
node*ptr=head;
while(ptr->next!=temp){
ptr=ptr->next;
}
ptr->next=temp->next;
delete temp;
}
}
return head;
}
int main()
{
int n1 ,n2,cnum;
node*head=NULL;
cout<<"\n 1.Add members.\n2.Delete members.\n3.Enter number action:";
cin>>cnum;
if(cnum==1){
cout<<"How many members do you wish to add>\n";
cin>>n1;
cout<<"\n1.beginnig\n2.middle\n3.end\nEnter Location to add?";
cin>>n2;
if(n2 == 1){
for(int i = 1 ; i <= n1;n1++){
cout<<"\nPlease enter member";
cin>>ele;
head=insertNodeBeg(head,ele)
}
if(n2==2){
for(int i = 1 ; i <= n1;n1++){
cout<<"\nPlease enter member";
cin>>ele;
cout<<"Enter Location";
cin>>loc;
head=insertNodeAfter(head, loc,ele)
}
if(n2 == 3){
for(int i = 1 ; i <= n1;n1++){
cout<<"\nPlease enter member";
cin>>ele;
head=insertNodeEnd(head,ele);}

else{
return 0;
}
}}}}
f(cnum == 2){
cout<<"How many members do you wish to delete>\n";
cin>>n1;
for(int i = 1; i <= n1;i++){
cout<<"enter members to delete>\n";
cin>>ele;
head=deleteNode(head,ele);
}
}
return 0;
}


and here are the errors:

||=== Build: Debug in Question 1 (compiler: GNU GCC Compiler) ===|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|7|error: 'deque' does not name a type|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp||In function 'node* insertNodeAfter(node*, int, int)':|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|53|error: 'searchNode' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|64|error: 'tmep' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp||In function 'node* deleteNode(node*, int)':|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|71|error: 'searchNode' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp||In function 'int main()':|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|105|error: 'ele' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|111|error: 'ele' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|113|error: 'loc' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|119|error: 'ele' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|122|error: expected '}' before 'else'|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|126|error: expected constructor, destructor, or type conversion before '(' token|
||=== Build failed: 10 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Last edited on
@mo13,
You should actually READ your error messages.

It would probably also be a good idea to write your own code, rather than attempting to cobble it together from other sources.
It appears to be heavily based (but badly copied) from
https://csegeek.com/csegeek/view/tutorials/algorithms/linked_list/list_operations.php


C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|7|error: 'deque' does not name a type|

You need header
#include <deque>
But what on earth were you planning to do with this anyway?


C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|53|error: 'searchNode' was not declared in this scope|

That's perfectly true, isn't it? I can't see anywhere in your program that you either declare or define searchNode ... you need to write this routine.


C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|64|error: 'tmep' was not declared in this scope|

"tmep" ... is that really what you meant to call a variable, ... or have you mistyped something ...?


C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|113|error: 'loc' was not declared in this scope|
C:\Users\muhammad\Desktop\progrsmming assessemnt\Programming 6\Question 1\main.cpp|119|error: 'ele' was not declared in this scope|

"loc" and "ele" are not declared in this scope ... because you haven't declared them!



PLEASE, PLEASE, PLEASE use CODE TAGS.


You don't really seem to be following what is specified in your assignment.


Actually, I've just had a look at your previous thread.
(a) You've completely ignored the very good advice that @Thomas1965 and @dhayden gave you there.
(b) "Your" code in that thread is effectively ripped from StackOverflow.
(c) "Your" code in this thread is also not your own.
Last edited on
It's probably a good idea to put the code in the right format so it's easy to read.
There was obviously little effort and thought put into this, I'm not sure how you can expect others to put in effort to help when you're not even trying.

And like @lastchance noted, you've ripped this from another website. You will learn a lot more from writing your own code and even if it looks like a mess, at least you will understand it.
tisk tisk, I would've reported this for dupe threading.
Topic archived. No new replies allowed.