update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
47
.config/Code/User/History/47873956/0Sl0.cpp
Normal file
47
.config/Code/User/History/47873956/0Sl0.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
46
.config/Code/User/History/47873956/2EHq.cpp
Normal file
46
.config/Code/User/History/47873956/2EHq.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
81
.config/Code/User/History/47873956/2b7k.cpp
Normal file
81
.config/Code/User/History/47873956/2b7k.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
48
.config/Code/User/History/47873956/2ckh.cpp
Normal file
48
.config/Code/User/History/47873956/2ckh.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T> temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
size++;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T> newNode = head;
|
||||
for(int i=0;i<size;i++){
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
54
.config/Code/User/History/47873956/2eO0.cpp
Normal file
54
.config/Code/User/History/47873956/2eO0.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/6oPo.cpp
Normal file
47
.config/Code/User/History/47873956/6oPo.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = *(newNode.next);
|
||||
}
|
||||
Node<T>* temp = newNode.next;
|
||||
newNode = *(newNode.next);
|
||||
temp->next = &newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
// list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/9Lx2.cpp
Normal file
47
.config/Code/User/History/47873956/9Lx2.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr)
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
52
.config/Code/User/History/47873956/9e13.cpp
Normal file
52
.config/Code/User/History/47873956/9e13.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
83
.config/Code/User/History/47873956/CCXZ.cpp
Normal file
83
.config/Code/User/History/47873956/CCXZ.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(temp->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
if(index == -1) return false;
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data<<" ";
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.insertAfterValue(3, 10);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
81
.config/Code/User/History/47873956/CMQ7.cpp
Normal file
81
.config/Code/User/History/47873956/CMQ7.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/Ce9o.cpp
Normal file
47
.config/Code/User/History/47873956/Ce9o.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = *(newNode.next);
|
||||
}
|
||||
Node<T>* temp = newNode.next;
|
||||
newNode = *(newNode.next);
|
||||
temp->next = &newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
// list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/DOxn.cpp
Normal file
47
.config/Code/User/History/47873956/DOxn.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
80
.config/Code/User/History/47873956/DSFG.cpp
Normal file
80
.config/Code/User/History/47873956/DSFG.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value){
|
||||
int index = search(value);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
54
.config/Code/User/History/47873956/Dx4D.cpp
Normal file
54
.config/Code/User/History/47873956/Dx4D.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
53
.config/Code/User/History/47873956/EoKr.cpp
Normal file
53
.config/Code/User/History/47873956/EoKr.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/GmJO.cpp
Normal file
47
.config/Code/User/History/47873956/GmJO.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
48
.config/Code/User/History/47873956/H8l4.cpp
Normal file
48
.config/Code/User/History/47873956/H8l4.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
53
.config/Code/User/History/47873956/JiRF.cpp
Normal file
53
.config/Code/User/History/47873956/JiRF.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
54
.config/Code/User/History/47873956/LcmD.cpp
Normal file
54
.config/Code/User/History/47873956/LcmD.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(2,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/MsQJ.cpp
Normal file
47
.config/Code/User/History/47873956/MsQJ.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node(data, nullptr)
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
48
.config/Code/User/History/47873956/Npml.cpp
Normal file
48
.config/Code/User/History/47873956/Npml.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T> temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
size++;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T> newNode = *head;
|
||||
for(int i=0;i<size;i++){
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
58
.config/Code/User/History/47873956/OjCe.cpp
Normal file
58
.config/Code/User/History/47873956/OjCe.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
49
.config/Code/User/History/47873956/PopK.cpp
Normal file
49
.config/Code/User/History/47873956/PopK.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
if(position > 0){
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/Se48.cpp
Normal file
47
.config/Code/User/History/47873956/Se48.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = *(newNode.next);
|
||||
}
|
||||
Node<T>* temp = newNode.next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
53
.config/Code/User/History/47873956/U5pH.cpp
Normal file
53
.config/Code/User/History/47873956/U5pH.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
54
.config/Code/User/History/47873956/Us6x.cpp
Normal file
54
.config/Code/User/History/47873956/Us6x.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
48
.config/Code/User/History/47873956/VnYm.cpp
Normal file
48
.config/Code/User/History/47873956/VnYm.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/WNCY.cpp
Normal file
47
.config/Code/User/History/47873956/WNCY.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
83
.config/Code/User/History/47873956/Xhfj.cpp
Normal file
83
.config/Code/User/History/47873956/Xhfj.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
cout<<index<<endl;
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data<<" ";
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.insertAfterValue(3, 10);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
82
.config/Code/User/History/47873956/Yh5D.cpp
Normal file
82
.config/Code/User/History/47873956/Yh5D.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.insertAfterValue(3, 10);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
50
.config/Code/User/History/47873956/aFJg.cpp
Normal file
50
.config/Code/User/History/47873956/aFJg.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/bUJq.cpp
Normal file
47
.config/Code/User/History/47873956/bUJq.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
49
.config/Code/User/History/47873956/bW7E.cpp
Normal file
49
.config/Code/User/History/47873956/bW7E.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
if(position > 0){
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
76
.config/Code/User/History/47873956/c2Kv.cpp
Normal file
76
.config/Code/User/History/47873956/c2Kv.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(head->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/cPFX.cpp
Normal file
47
.config/Code/User/History/47873956/cPFX.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/ck4E.cpp
Normal file
47
.config/Code/User/History/47873956/ck4E.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node(data, nullptr)
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
46
.config/Code/User/History/47873956/dFWu.cpp
Normal file
46
.config/Code/User/History/47873956/dFWu.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T> temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
1
.config/Code/User/History/47873956/entries.json
Normal file
1
.config/Code/User/History/47873956/entries.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"resource":"file:///home/rafayahmad/Stuff/Coding/C%2B%2B/DS/lab3/q2.cpp","entries":[{"id":"2ckh.cpp","timestamp":1725878816971},{"id":"Npml.cpp","timestamp":1725878830929},{"id":"zuNX.cpp","timestamp":1725878865528},{"id":"dFWu.cpp","timestamp":1725878909163},{"id":"gNGL.cpp","timestamp":1725878943401},{"id":"2EHq.cpp","timestamp":1725878962183},{"id":"DOxn.cpp","timestamp":1725878984719},{"id":"0Sl0.cpp","timestamp":1725879010361},{"id":"cPFX.cpp","timestamp":1725879023106},{"id":"lOrf.cpp","timestamp":1725879069996},{"id":"bUJq.cpp","timestamp":1725879122119},{"id":"Se48.cpp","timestamp":1725879154084},{"id":"nrVj.cpp","timestamp":1725879181725},{"id":"6oPo.cpp","timestamp":1725879203229},{"id":"Ce9o.cpp","timestamp":1725879317350},{"id":"VnYm.cpp","timestamp":1725879335571},{"id":"H8l4.cpp","timestamp":1725879365954},{"id":"MsQJ.cpp","timestamp":1725879411248},{"id":"ck4E.cpp","timestamp":1725879421993},{"id":"9Lx2.cpp","timestamp":1725879438771},{"id":"qujE.cpp","timestamp":1725879452009},{"id":"pc14.cpp","timestamp":1725879487928},{"id":"stUh.cpp","timestamp":1725879502180},{"id":"PopK.cpp","timestamp":1725879539337},{"id":"GmJO.cpp","timestamp":1725879553719},{"id":"bW7E.cpp","timestamp":1725879647220},{"id":"WNCY.cpp","timestamp":1725879689021},{"id":"aFJg.cpp","timestamp":1725879711067},{"id":"9e13.cpp","timestamp":1725879722793},{"id":"EoKr.cpp","timestamp":1725879746802},{"id":"JiRF.cpp","timestamp":1725880116131},{"id":"lbR6.cpp","timestamp":1725880189449},{"id":"U5pH.cpp","timestamp":1725880238296},{"id":"fGEU.cpp","timestamp":1725880248596},{"id":"LcmD.cpp","timestamp":1725880334703},{"id":"Us6x.cpp","timestamp":1725880354606},{"id":"Dx4D.cpp","timestamp":1725880376640},{"id":"2eO0.cpp","timestamp":1725880393116},{"id":"OjCe.cpp","timestamp":1725880485673},{"id":"wb2Q.cpp","timestamp":1725880511809},{"id":"rq01.cpp","timestamp":1725880545735},{"id":"c2Kv.cpp","timestamp":1725880644791},{"id":"DSFG.cpp","timestamp":1725880700091},{"id":"2b7k.cpp","timestamp":1725880742437},{"id":"CMQ7.cpp","timestamp":1725880780046},{"id":"Yh5D.cpp","timestamp":1725880797976},{"id":"Xhfj.cpp","timestamp":1725880826481},{"id":"gQYL.cpp","timestamp":1725880926528},{"id":"CCXZ.cpp","timestamp":1725880956915},{"id":"ijZF.cpp","timestamp":1725881460976}]}
|
53
.config/Code/User/History/47873956/fGEU.cpp
Normal file
53
.config/Code/User/History/47873956/fGEU.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
46
.config/Code/User/History/47873956/gNGL.cpp
Normal file
46
.config/Code/User/History/47873956/gNGL.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode.next;
|
||||
}
|
||||
Node<T> temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
83
.config/Code/User/History/47873956/gQYL.cpp
Normal file
83
.config/Code/User/History/47873956/gQYL.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(temp->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
cout<<index<<endl;
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data<<" ";
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.insertAfterValue(3, 10);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
83
.config/Code/User/History/47873956/ijZF.cpp
Normal file
83
.config/Code/User/History/47873956/ijZF.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
|
||||
int search(T value){
|
||||
Node<T>* temp = head;
|
||||
for(int i=0;i<size;i++){
|
||||
if(temp->data == value) return i;
|
||||
temp = temp->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insertAfterValue(T value, T data){
|
||||
int index = search(value);
|
||||
if(index == -1) return false;
|
||||
return insertAtPosition(index+1, data);
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data<<" ";
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtHead(1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtEnd(5);
|
||||
list.insertAfterValue(3, 10);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/lOrf.cpp
Normal file
47
.config/Code/User/History/47873956/lOrf.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = ;
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
53
.config/Code/User/History/47873956/lbR6.cpp
Normal file
53
.config/Code/User/History/47873956/lbR6.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/nrVj.cpp
Normal file
47
.config/Code/User/History/47873956/nrVj.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = *(newNode.next);
|
||||
}
|
||||
Node<T>* temp = newNode.next;
|
||||
newNode = *(newNode.next);
|
||||
temp->next = &newNode;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/pc14.cpp
Normal file
47
.config/Code/User/History/47873956/pc14.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
// list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/qujE.cpp
Normal file
47
.config/Code/User/History/47873956/qujE.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
66
.config/Code/User/History/47873956/rq01.cpp
Normal file
66
.config/Code/User/History/47873956/rq01.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
void insertAtEnd(T data){
|
||||
insertAtPosition(size, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
47
.config/Code/User/History/47873956/stUh.cpp
Normal file
47
.config/Code/User/History/47873956/stUh.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
62
.config/Code/User/History/47873956/wb2Q.cpp
Normal file
62
.config/Code/User/History/47873956/wb2Q.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
public:
|
||||
T data;
|
||||
Node<T>* next;
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
head = new Node<T>(data, nullptr);
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void insertAtHead(T data){
|
||||
insertAtPosition(0, data);
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
if(position < 0 || position > size) return false;
|
||||
Node<T>* newNode = new Node(data, head);
|
||||
if(position == 0){
|
||||
head = newNode;
|
||||
}
|
||||
else{
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode->next = newNode->next->next;
|
||||
}
|
||||
Node<T>* temp = newNode->next;
|
||||
newNode->next = newNode->next->next;
|
||||
temp->next = newNode;
|
||||
}
|
||||
size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T>* temp = head;
|
||||
while(temp != nullptr){
|
||||
cout<<temp->data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
list.insertAtPosition(1, 3);
|
||||
list.insertAtPosition(3,5);
|
||||
list.printList();
|
||||
|
||||
return 0;
|
||||
}
|
49
.config/Code/User/History/47873956/zuNX.cpp
Normal file
49
.config/Code/User/History/47873956/zuNX.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
class Node{
|
||||
T data;
|
||||
Node<T>* next;
|
||||
public:
|
||||
Node(T data, Node<T>* next) : data(data), next(next){}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LinkedList{
|
||||
Node<T>* head;
|
||||
int size;
|
||||
public:
|
||||
LinkedList(T data){
|
||||
Node<T> node(data, nullptr);
|
||||
head = &node;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
bool insertAtPosition(int position, T data){
|
||||
Node<T> newNode(data, head);
|
||||
for(int i=0;i<position-1;i++){
|
||||
newNode = newNode->next;
|
||||
}
|
||||
Node<T> temp = newNode->next;
|
||||
newNode = newNode->next;
|
||||
temp->next = newNode;
|
||||
size++;
|
||||
}
|
||||
|
||||
void printList(){
|
||||
Node<T> temp = *head;
|
||||
for(int i=0;i<size;i++){
|
||||
cout<<temp.data;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
LinkedList<int> list(1);
|
||||
list.insertAtPosition(0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue