diff --git a/Lab task2/Lab task2.vcxproj b/Lab task2/Lab task2.vcxproj new file mode 100644 index 0000000..5df596a --- /dev/null +++ b/Lab task2/Lab task2.vcxproj @@ -0,0 +1,136 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {F515F5A2-7B39-4264-8A6D-58D4741B8ACE} + Labtask2 + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab task2/Lab task2.vcxproj.filters b/Lab task2/Lab task2.vcxproj.filters new file mode 100644 index 0000000..48b305d --- /dev/null +++ b/Lab task2/Lab task2.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/Lab task2/Lab task2.vcxproj.user b/Lab task2/Lab task2.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Lab task2/Lab task2.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Lab task2/functions.cpp b/Lab task2/functions.cpp new file mode 100644 index 0000000..71b7448 --- /dev/null +++ b/Lab task2/functions.cpp @@ -0,0 +1,219 @@ +#include +#include"List.h" +using namespace std; + +void list::insertion() +{ + node* newnode; + int num; + newnode = new node(); + cout << "please enter the value you want to insert....." << endl; + cin >> num; + newnode->set(num); + newnode->setnext(nullptr); + newnode->setprev(nullptr); + + cout << "Enter the choice how you want to insert the value?" << endl; + cout << " if you want to insert after location press 1\n And if you want to insert value before location press 2" << endl; + int ch; + cin >> ch; + switch (ch) + { + case 1: + if (headnode == nullptr) { + headnode = newnode; + currentnode = newnode; + } + else { + newnode->setprev(currentnode); + newnode->setnext(currentnode->getnext()); + (currentnode->getnext())->setprev(newnode); + currentnode->setnext(newnode); + currentnode = newnode; + } + size++; + break; + case 2: + if (headnode == nullptr) { + headnode = newnode; + currentnode = newnode; + } + else if (currentnode!=headnode) { + + newnode->setprev(currentnode->getprev()); + newnode->setnext(currentnode); + (currentnode->getprev())->setnext(newnode); + currentnode->setprev(newnode); + currentnode = newnode; + } + else { + currentnode->setprev(newnode); + newnode->setnext(currentnode); + newnode->setprev(nullptr); + newnode = headnode; + newnode = currentnode; + } + + + + + size++; + break; + default: + cout << "please enter the correct choice" << endl; + break; + + + } +} +void list::deletion() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + if (find() == 1) { + node* temp = currentnode; + (currentnode->getprev())->setnext(currentnode->getnext()); + (currentnode->getnext())->setprev(currentnode->getprev()); + currentnode = currentnode->getnext(); + delete temp; + } + else { + cout << "value not found" << endl; + + } + } +} +void list::get() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + cout << "Current element is " << currentnode->get() << endl << "Current index is " << currentnode->getnext() << endl; + } +} +void list::start() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + currentnode = headnode; + cout << "Current element is " << currentnode->get() << endl << "Current index is " << currentnode->getnext() << endl; + } +} + + + +void list::update() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + if (find() == 1) + { + int update; + cout << "Enter the value to be updated......!!!!!!" << endl; + cin >> update; + + currentnode->set(update); + } + cout << "your value has been updated thanks!!!!!!" << endl; + } +} +void list::tail() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + while (currentnode->getnext() != nullptr) { + currentnode = currentnode->getnext(); + + } + cout << "you are now at the end" << endl; + } +} +void list::back() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + currentnode = currentnode->getprev(); + cout << "you are now on this " << currentnode->get() << " element" << endl; + } + } +void list::next() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + currentnode = currentnode->getnext(); + cout << "you are now on this " << currentnode->get() << " element" << endl; + } + } +void list::display() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + node* tem = headnode; + while (tem != nullptr) + { + cout << tem->get() << endl; + tem = tem->getnext(); + } + } +} +void list::length() +{ + if (headnode == nullptr) { + cout << "List is empty" << endl; + } + else { + cout << "length of list is:" << size << endl; + } + } +void list::exit() +{ + +} +int list::find() +{ + int flag = 0; + if (headnode == nullptr) { + + cout << "List is empty" << endl; + + } + else { + + int num; + cout << "Enter the value that you want to find" << endl; + cin >> num; + node* temp = headnode; + + while (temp != nullptr) + { + if (num == temp->get()) + { + currentnode = temp; + + flag = 1; + break; + + } + else + { + flag = 0; + } + } + } + return flag; +} \ No newline at end of file diff --git a/Lab task2/list.h b/Lab task2/list.h new file mode 100644 index 0000000..edcac5e --- /dev/null +++ b/Lab task2/list.h @@ -0,0 +1,36 @@ +#pragma once +#pragma once +#include"node.h" +class list { +private: + int size; + node* currentnode; + node* headnode; + + +public: + list() { + size = 0; + currentnode = nullptr; + headnode = nullptr; + + } + ~list() { + + } + + + void insertion(); + void deletion(); + int find(); + void exit(); + void next(); + void back(); + void tail(); + void display(); + void start(); + void length(); + void get(); + void update(); + +}; diff --git a/Lab task2/main.cpp b/Lab task2/main.cpp new file mode 100644 index 0000000..46baf36 --- /dev/null +++ b/Lab task2/main.cpp @@ -0,0 +1,90 @@ +#include +#include +#include"list.h" +using namespace std; +int main() { + int op; + list L; + do { + + cout << " --------- Please enter choice between 1 to 12 For Different Operations----------- " << endl; + + cout << " For insertion please press 1 " << endl; + cout << " For Deletion please press 2 " << endl; + cout << " For Update(replace the element) please press 3 " << endl; + cout << " For Start please press 4" << endl; + cout << " For Next please press 5" << endl; + cout << " For Back please press 6" << endl; + cout << " For Tail please press 7" << endl; + cout << " For Find please press 8" << endl; + cout << " For length please press 9" << endl; + cout << " For Get(display current index and element) please press 10" << endl; + cout << " For Display list please press 11" << endl; + cout << " For Exit please press 12" << endl; + cin >> op; + switch (op) { + case 1: + L.insertion(); + + break; + case 2: + + + L.deletion(); + break; + case 3: + + L.update(); + break; + case 4: + + L.start(); + break; + case 5: + + L.next(); + break; + case 6: + + L.back(); + break; + case 7: + + L.tail(); + break; + case 8: + + if (L.find() == 1) + { + cout << "value is found" << endl; + + } + else { + cout << "value is not found try again" << endl; + } + break; + + case 9: + + L.length(); + break; + case 10: + + L.get(); + break; + + case 11: + + L.display(); + break; + case 12: + + L.exit(); + break; + + + + } + } while (op != 12); + return 0; +} \ No newline at end of file diff --git a/Lab task2/node.h b/Lab task2/node.h new file mode 100644 index 0000000..1bd9925 --- /dev/null +++ b/Lab task2/node.h @@ -0,0 +1,38 @@ + +#pragma once +class node +{ + int object; + node* next; + node* prev; + +public: + node() { + object = 0; + next = nullptr; + prev = nullptr; + } + ~node() + { + } + void set(int x) + { + object = x; + } + int get() { + return object; + } + void setnext(node* n) { + next = n; + } + node* getnext() { + return next; + } + void setprev(node* p) { + prev = p; + } + node* getprev() { + return prev; + } + +}; \ No newline at end of file