in want to edit the code in such a way tht the user can enter upto 10 values maximum..need help pls ...

#include <iostream>
#include <iomanip>
using namespace std;

struct node

{

int info;

struct node* next;

}*front,*rear;

void enqueue(int elt);

int dequeue();

void display();

void main()

{

int ch,elt;

rear=NULL;

front=NULL;


while(1)

{

cout<<"Enter:\t1->Insert\t2->Delete\t3->Display\t4->Exit\n";

cin>>ch;

switch(ch)

{

case 1:

	cout<<"Enter The Values: ";

cin>>elt;
enqueue(elt);
break;

case 2:

elt=dequeue();

cout<<"The deleted value = "<<elt<<"\n";

break;

case 3:

display();
cout<<"\n";
break;

default:

cout<<"~~~Exit~~~";

cin.get();cin.get();

exit(0);

break;

}

}

}

void enqueue(int elt)

{

struct node *p;

p=(struct node*)malloc(sizeof(struct node));

p->info=elt;
p->next=NULL;

if(rear==NULL||front==NULL)

front=p;

else

rear->next=p;

rear=p;

}

int dequeue()

{

struct node *p;

int elt;

if(front==NULL||rear==NULL)

{

cout<<"\nThe Queue is empty. Cannot delete further.";

cin.get();cin.get();

exit(0);

}

else

{

p=front;

elt=p->info;

front=front->next;

free(p);

}

return(elt);

}

void display()

{

struct node *t;

t=front;

while(front==NULL||rear==NULL)

{

cout<<"\nQueue is empty";

cin.get();cin.get();

exit(0);

}
cout<<"The numbers in the queue are-->";
while(t!=NULL)

{
cout<<t->info<<"\t";
t=t->next;

}

}

Why don't you keep track of how many values the user has entered, and use some mechanism to see if that number's 10?

a

Why don't you keep track of how many values the user has entered, and use some mechanism to see if that number's 10?

i cannot think of anything how to keep the track of that or allow the user to input in the array....can u pls help me by editing it...it would be gr8 favor..thanks a lot

Example :

#include <iostream>

using namespace std;

int main()
{
   int val[4] = {1,2,3,4};

   int limit = 2;

   for(int i = 0; i < limit; i++)
     {
         cout<<"Enter value : ";
         cin >> val[i]
      }
   return 0;
}

Example :

#include <iostream>

using namespace std;

int main()
{
   int val[4] = {1,2,3,4};

   int limit = 2;

   for(int i = 0; i < limit; i++)
     {
         cout<<"Enter value : ";
         cin >> val[i]
      }
   return 0;
}

hey can u pls edit in my program bcz i m really afraid tht i might mess up d whole program...it already took me too long to write the program...thank u n i appreciate ur help

hey can u pls edit in my program bcz i m really afraid tht i might mess up d whole program...it already took me too long to write the program...thank u n i appreciate ur help

Then copy and paste it into a text file, and save it. Then start playing around with it. If you mess up too much, then just copy and paste the
original content from the text file.

hey can someone tell me how to make 10 nodes in the code tht i have made...thts the one way i could think of...

hey can someone tell me how to make 10 nodes in the code tht i have made...thts the one way i could think of...

Try figuring it out yourself. Then maybe you'll learn something.

Try figuring it out yourself. Then maybe you'll learn something.

dont u think while writing this code i must have not ried it several times...i did n couldnt do it thts d reason why m here asking for help...ita request if sum1 can really help...maybe in my other projects i wouldnt need d same help bcz by seeing the code i can learn it too

Before fixing your code, you should fix your grammar.

Is it necessary to use the struct data type in your code? All you seem to be doing is inputting and deleting (setting to 0) int values. I would suggest a simple array.

Tell me what you are trying to accomplish, so I do not have to try to reverse engineer your code. To me it seems as if you are trying to enter up to 10 integer values that would not consist of 0. I think I can help you if we don't need the struct data type because I don't understand it.

Is it necessary to use the struct data type in your code? All you seem to be doing is inputting and deleting (setting to 0) int values. I would suggest a simple array.

Tell me what you are trying to accomplish, so I do not have to try to reverse engineer your code. To me it seems as if you are trying to enter up to 10 integer values that would not consist of 0. I think I can help you if we don't need the struct data type because I don't understand it.

i just have to use linked-list to implement a queue and write a client code to insert 10 numbers then remove them (display then remove).

Oh I'm sorry I don't know how to do that. Good Luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.