- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Implementing stack and Lucas series in C++
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 03:22 PM
тАО09-10-2009 03:22 PM
Can anybody help me for these programs.
1) Write a C++ program to generate Lucas series
2) Write a C++ program to accept the student's information of UG
students in a college. Also include the functions for searching student
information and updating the existing information.
3) Write a C++ program to create a doubly linked list and support the
following operation:
i). Insertion at the rear end
ii). Insertion at the specific position
iii). Traversing the entire list and displaying the nodes.
iv). Counting the occurrence of duplicate nodes
4) Write a C++ program to implement Stack data structure
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 04:11 PM
тАО09-10-2009 04:11 PM
Re: Implementing stack and Lucas series in C++
I'm sorry but this sounds like a HOMEWORK exercise for a course you are taking.
Homework assignments are not what this Forum is about.
You will learn far more by trying yourself. Good luck.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-11-2009 04:22 AM
тАО09-11-2009 04:22 AM
SolutionThat's called template std::list.
>iii). Traversing the entire list and displaying the nodes.
>iv). Counting the occurrence of duplicate nodes
>4) Write a C++ program to implement Stack data structure
That's called template std::stack.
- Tags:
- containers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-11-2009 05:38 AM
тАО09-11-2009 05:38 AM
Re: Implementing stack and Lucas series in C++
Seems they responded w/ "do your own homework" there as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2009 12:00 AM
тАО09-13-2009 12:00 AM
Re: Implementing stack and Lucas series in C++
Lucas:
#include
void main(){
int L0,L1,temp,MAX;
L0=2;
L1=1;
cout <<" Enter the number of max no of values in series";
cin >> MAX ;
cout << LO << L1;
for(i=0;i
L0=L1;
L1=temp;
cout << L1;
}
}
=============================================================
doubly link
#include
class node
{
public:
int value; //value stored in the node
node *next; //pointer to next node
node *prev; //pointer to previous node
};
class dlist
{
public:
node *front; //pointer to front of list
node *back; //pointer to back of list
dlist()
{
front=NULL;
back=NULL;
}
void insertFront(int value);
void insertBefore(int value,node *nodeB);
void insertAfter(int value,node *nodeA);
void printDListFront();
};
//insert a node before the front node
void dlist::insertFront (int value)
{
node *newNode;
if(this->front==NULL)
{
newNode=new node();
this->front=newNode;
this->back =newNode;
newNode->prev=NULL;
newNode->next=NULL;
newNode->value=value;
}
else
{
insertBefore(value,this->front );
}
}
//insert a node at specified position nodeB
void dlist::insertAfter(int value,node *nodeB)
{
node *newNode;
newNode=new node();
newNode->next= nodeB->next ;
newNode->prev =nodeB;
newNode->value =value;
if(nodeB->next==NULL)
{
cout<<"\n "<< endl;
this->back =newNode;
}
nodeB->next=newNode;
cout<<"2"<
}
//Print the list from front
void dlist::printDListFront()
{
node* curr2;
curr2= this->front;
cout<<"\n-----\n";
cout<<"Queue\n";
cout<<"-----\n";
//cout<<"size:"<
{
cout<<" |"<
curr2=curr2->next;
}
cout<
void main()
{
dlist *st ;
st= new dlist();
st->insertBack(8);
st->printDListFront ();
st->insertBack(5);
st->printDListFront ();
st->insertBack(6);
st->printDListFront ();
st->insertFront(1) ;
st->printDListFront ();
st->insertFront(3) ;
st->printDListFront ();
st->insertBack(7);
st->printDListFront ();
st->removeFront();
st->printDListFront ();
st->removeBack();
st->printDListFront ();
}
====================================================================================================================
STUDENT INFORMATION
include< iostream.h>
#include< conio.h>
class student
{
int count;
struct stud
{
int rollno;
char name[10];
float marks;
}s[10];
public:
void getcount(void);
void getdata(void);
void putdata(void);
void findranker(void);
};
void student::getcount(void)
{
cout< < "Enter no of Students:";
cin>>count;
}
void student::getdata(void)
{
int i;
for(i=0;i< count;i++)
{
cout< < "Name: ";
cin>>s[i].name;
cout< < "Roll no:";
cin>>s[i].rollno;
cout< < "marks:";
cin>>s[i].marks;
}
}
void student::putdata(void)
{
int i;
cout< < "_______________________________________"< < endl;
cout< < "Name\t"< < "Roll no.\t"< < "Marks"< < endl;
cout< < "---------------------------------------"< < endl;
for(i=0;i< count;i++)
cout< < s[i].name< < "\t"< < s[i].rollno< < "\t\t"< < s[i].marks< < endl;
cout< < "---------------------------------------";
}
void student::findranker(void)
{
int i,loc=0;
float top;
top=s[0].marks;
for(i=0;i< count;i++)
{
if(s[i].marks>top)
{
top=s[i].marks;
loc=i;
}
}
cout< < "\nThe Ranker Is:";
cout< < s[loc].name;
}
void main()
{
clrscr();
student s;
s.getcount();
s.getdata();
s.putdata();
s.findranker();
getch();
}
================================================================================================================
STACK OPERATIONS
#include
#include
#include
#include
class element
{
public:
int value;
element* next;
};//class element
class stack
{
public:
int size;
element* current;
stack()
{
size=0;
current=NULL;
}//default constructor
bool push(int,element*);
bool pop();
bool isEmpty();
int getStackSize();
void printStackSize();
void printStackElements(element*);
void printStackMenu();
};
bool stack::push(int ele,element* temp)
{
temp=new element;
if(current==NULL)
{
temp->next=NULL;
}
else
{
temp->next=current;
}
temp->value=ele;
current=temp;
printf("%d inserted\n\n",ele);
size++;
return false;
}
bool stack::pop()
{
if(isEmpty())
{
cout<<"\nStack is Empty\n";
return false;
}
else
{
cout<<"\n Element To POP :"<
cout<<"\n Before POP";
printStackElements(current);
current=current->next;
cout<<"\n After POP";
printStackElements(current);
size=size--;
}
return true;
}
bool stack::isEmpty()
{
if(getStackSize()==0)
return true;
return false;
}
int stack::getStackSize()
{
return size;
}//returns size of the stack
void stack::printStackSize()
{
cout<<"\nThe Size of the Stack:"<
void stack::printStackElements(element* base)
{
element* curr2;
curr2= base;
cout<<"\n-----\n";
cout<<"STACK\n";
cout<<"-----\n";
while(curr2!=NULL)
{
cout<<" |"<
curr2=curr2->next;
}
}// print the stack
void stack::printStackMenu()
{
cout<<"Welcome to Stack \n";
cout<<"1.Push an element\n";
cout<<"2.Pop an element\n";
cout<<"3.Display Stack\n";
cout<<"4.Size Of Stack\n";
cout<<"5.Exit\n";
}
void main()
{
stack st;
char Option=0;
int val;
while(1)
{
st.printStackMenu();
cin>>Option;
switch(Option)
{
case '1':
cout<<"Enter a Number \n";
cin>>val;
st.push(val,st.current);
break;
case '2':
st.pop();
break;
case '3':
st.printStackElements(st.current);
break;
case '4':
st.printStackSize();
break;
case '5':
exit(0);
break;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2009 12:02 AM
тАО09-13-2009 12:02 AM