Hi ive made a code does the following:
- user makes a list of items
- user adds more items to the list
- list is displayed
it uses Linked-Lists.
here is the code
#include <iostream>
using namespace std;
struct vote
{
char product[10];
vote *votePtr;
};
void addNodes(vote *&startPtr,vote *¤t, int total)
{
cout<<"enter number of products to add to list: ";
cin>>total;
{
vote *temp, *temp2;
for(int i=0;i<total;i++)
{
temp=new vote;
cout<<"enter product name:";
cin>>temp->product;
temp->votePtr=NULL;
if(startPtr==NULL)
{
startPtr=temp;
current=startPtr;
}
else
{
temp2=startPtr;
while(temp2->votePtr!=NULL)
temp2=temp2->votePtr;
temp2->votePtr=temp;
}
}
}
}
void insert(vote *&startPtr,vote *¤t, int more)
{
cout<<"How many more products you want to add? ";
cin>>more;
{
vote *temp, *temp2;
for(int i=0;i<more;i++)
{
temp=new vote;
cout<<"enter product name:";
cin>>temp->product;
temp->votePtr=NULL;
if(startPtr==NULL)
{
startPtr=temp;
current=startPtr;
}
else
{
temp2=startPtr;
while(temp2->votePtr!=NULL)
temp2=temp2->votePtr;
temp2->votePtr=temp;
}
}
}
}
void displayList(vote *&startPtr)
{
vote *yes;
yes=startPtr;
cout<<"RESULTS"<<endl;
while(yes!=NULL)
{
cout<<yes->product<<" "<<endl;
yes=yes->votePtr;
}
}
void del()
{
}
int main() {
vote *startPtr=NULL;
vote *current;
int total=0;
int more=0;
addNodes(startPtr,current,total);
insert(startPtr,current,more);
del();
displayList(startPtr);
system("pause");
return 0;
}
i left out del for delete. the user should also be able to delete an item they previously added so it wont be displayed at the end. i am confused on how i would go about this etc. everything else works.
any help is much appreciated.