- 1

Please help me i am stuck : Make stack data structure using link list without using( struck)(C++)

Write a C++ program to implement stack data structure using link list data structure. The required program needs to fulfill the following requirements. 1. Create a node(student) class to save the information(name and marks) of a student. 2. Create one or multiple stacks to save students, data into stack(s). Use linked list data structure for the implementation of stack. Take the choice operation from the user and perform the following task 1. To add a student in stack. 2. To remove a student from stack. 3. Display all students of stack. 4. Display top 3 position of students ( Descending order) 5. Press 5 or any other key to close the program. Note : only classes Student(Node) and stack are allowed. Importantly do not use struct for node. https://code.sololearn.com/cEfWnXwWfo03/?ref=app https://code.sololearn.com/cEfWnXwWfo03/?ref=app I tried to do it own my own but it is causing errors I will be very grateful if some can either solve it or tell me my mistakes. God bless you. Have a nice day.

4th Dec 2021, 3:46 PM
Anmol
Anmol - avatar
3 Answers
0
#include<iostream> using namespace std; int size=0; class Student{ public: string name; int marks; Student *nextStudent; void setName(string setn){ name=setn; } string getName(){ return name; } void setMarks(int setm){ marks=setm; } int getMarks(){ return marks; } void setNextStudent(Student *setAddress){ nextStudent=setAddress; } Student* getNextStudent(){ return nextStudent; } }; class Stack{ public: Student *headStudent=NULL; bool isEmpty(){ if(headStudent==NULL){ cout<<endl<<"Stack is Empty"<<endl; return true; } else{ return false; } } void push(){ string n; int m; Student *newNode=new Student; cout<<"Enter the name of Student: "<<endl; cin>>n; newNode->setName(n); cout<<"Enter the Marks of Student: "<<endl; cin>>m; newNode->setMarks(m); newNode->setNextStudent(NULL); if(headStudent==NULL){ headStudent=newNode; } else{ Student *ptr=headStudent; while ( ptr-> getNextStudent()!=NULL ) { ptr=ptr->getNextStudent(); } ptr->setNextStudent(newNode); } cout<<endl<<"Student Data saved successfully"<<endl; size++; } void pop(){ if(!isEmpty()){ Student *pre=headStudent; Student *ptr=headStudent; while (ptr->getNextStudent()!=NULL) { pre=ptr; ptr=ptr->getNextStudent();
7th Dec 2021, 8:57 AM
Mani Siddiqui
0
I tried to do my assignment as you guessed it is but I am getting errors.
7th Dec 2021, 11:24 AM
Anmol
Anmol - avatar