Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hindi talaga namin alam mam paano mag call at sa main banda :(
- // turuan nyo kame mam Thank you
- # include <iostream>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- template <typename A>
- class node{
- public:
- A data;
- node *next;
- };
- template <typename A>
- node<A>::node(A value){
- data=value;
- next=NULL;
- }
- template <typename A>
- class list{
- node *head, *tail;
- public:
- void addNode1(A &start); // beginning
- void addNode2(A &start ); //last
- void addNode3(A &start ); //anywhere
- void deleteNode();
- void displayNode();
- char name[50];
- int age;
- // const (A val);
- };
- /*template<typename A>
- list<A>::const (A val)
- {
- nxtNode=0;
- }*/
- /*class node{
- public:
- node<A>(A value);;
- private:
- A data;
- node<A> *nxtNode;
- };*/
- class start{
- public:
- node *firstNode;
- int listSize;
- }h;
- template<typename A>
- void list<A>::addNode1(A &start)
- {
- // node <int> *addnode = new node(value);
- node *addnode=new node;
- node *temp;
- temp=head;
- head= addnode;
- cout<<endl<<"List"<<endl<<endl;
- cin.ignore();
- cout<<"Enter your name: ";
- cin.getline(addnode->name,50);
- cout<<"Enter your age: ";
- cin>>addnode->age;
- cout<<"Enter your phone number: ";
- cin>>addnode->phoneNumber;
- cin.ignore();
- cout<<"Enter your address: ";
- cin.getline(addnode->address,50);
- addnode->nxt=NULL;
- addnode->nxt=temp;
- }
- template<typename A>
- void list<A>::addNode2(A &start)
- {
- node *temp;
- temp=head;
- node *addnode= new node;
- cout<<endl<<"List"<<endl<<endl;
- cin.ignore();
- cout<<"Enter your name: ";
- cin.getline(addnode->name,50);
- cout<<"Enter your age: ";
- cin>>addnode->age;
- cout<<"Enter your phone number: ";
- cin>>addnode->phoneNumber;
- cin.ignore();
- cout<<"Enter your address: ";
- cin.getline(addnode->address,50);
- addnode->nxt = NULL;
- cin.ignore();
- while(temp->nxt !=NULL)
- {
- temp=temp->nxt;
- }
- temp->nxt=addnode;
- }
- template<typename A>
- void list<A>::addNode3(A &start)
- {
- node *hopper=h.firstNode;
- node *addnode = new node;
- int pos=0;
- if(h.firstNode==0)
- {
- cout << "Enter your friend's name: ";
- cin.ignore();
- cin.getline(addnode->name,50);
- cout << "Enter your friend's age: ";
- cin >> addnode->age;
- addnode->next = 0;
- cin.ignore();
- h.firstNode=addnode;
- h.listSize=1;
- }
- else
- {
- cout << "You currently have " << h.listSize << " in your list." << endl;
- cout << "In what position do you wish to insert your new node? :";
- do
- {
- cin >> pos;
- if(pos <= 0 || pos > h.listSize+1)
- cout << endl << "You cannot insert a node in that position. Enter another position: ";
- }while(pos <= 0 || pos > h.listSize+1);
- int counter=1;
- cin.ignore();
- cout << "Enter your friend's name: ";
- cin.getline(addnode->name,50);
- cout << "Enter your friend's age: ";
- cin >> addnode->age;
- cin.ignore();
- if(pos==1)
- {
- addnode->next=h.firstNode;
- h.firstNode=addnode;
- }
- else
- {
- if(pos > h.listSize)
- {
- while(counter < pos-1)
- {
- hopper=hopper->next;
- counter++;
- }
- addnode->next=0;
- hopper->next=addnode;
- }
- else
- {
- while(hopper!=0)
- {
- if(counter==pos-1)
- break;
- hopper=hopper->next;
- counter++;
- }
- addnode->next=hopper->next;
- hopper->next=addnode;
- }
- }
- h.listSize++;
- }
- }
- template<typename A>
- void list<A>::deleteNode()
- {
- char name1 [50];
- node *temp=h.firstNode;
- node *preceeding=h.firstNode;
- node *target=0;
- cin.ignore();
- cout << "Enter friend's name to delete:" ;
- cin.getline(name1, 50);
- while(temp != 0)
- {
- if(strcmp(temp->name,name1)==0)
- {
- ChangeCase(temp->name);
- target=temp;
- break;
- }
- preceeding=temp;
- temp=temp->next;
- }
- if(target!=0)
- {
- if(target->next==0)
- {
- preceeding->next=0;
- delete target;
- }
- else
- {
- if(target==h.firstNode)
- {
- h.firstNode=target->next;
- delete target;
- }
- else
- {
- preceeding->next=target->next;
- delete target;
- }
- }
- cout << "Successfully deleted " << name1 << "'s record!" << endl;
- }
- else
- cout << "Your friend's record is not found! " << endl;
- system("pause");
- }
- template<typename A>
- void list<A>::displayNode()
- {
- node *display = h.firstNode;
- while(display != 0)
- {
- cout << display->name << " " << display->age << endl;
- display=display->next;
- }
- system("pause");
- }
- //template<typename A>
- void main (){
- int l;
- list <int> mylist;
- int c=0;
- h.listSize=0;
- h.firstNode=NULL;
- do{
- system("CLS");
- cout<<"\t\tMenu"<<endl;
- cout<<"[1]Add Node in the beginning"<<endl;
- cout<<"[2]Add Node in the End"<<endl;
- cout<<"[3]Choose your position"<<endl;
- cout<<"[4]Delete"<<endl;
- cout<<"[5]Display"<<endl;
- cout<<"[6]Exit"<<endl<<endl;
- cout<<endl;
- cout<<"Enter your choice: ";
- cin>>c;
- cout<<endl;
- switch(c){
- case 1:
- mylist.addNode1(l);
- break;
- case 2:
- // addNode2(h);
- break;
- case 3:
- // addNode3(h);
- break;
- case 4:
- // deleteNode();
- break;
- case 5:
- // displayNode();
- break;
- case 6:
- cout<<"buh bye!"<<endl;
- break;
- }
- }while(c!=6);
- }
- /*class list
- not class head
- class list
- tapos
- may dalawang node
- head and tail
- template<typename A>
- class node{
- public:
- A data;
- node *next;
- node(A value){
- data=value;
- next=NULL;
- }
- };
- 5 minutes agoJake Laurence Santiago
- ganun. pero una ang node bago ang list
- tapos
- para sa input
- node <int> *newnode = new node(int value here);
- pde din <char> <float> <double> or <bool>
- pero sa void main(){
- list l; lang */
Add Comment
Please, Sign In to add comment