Skip to content
Open

Dsa #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added himanshi-khatri-skit-B230490/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions himanshi-khatri-skit-B230490/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "macos-clang-arm64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "macos-clang-arm64",
"compilerArgs": [
""
]
}
],
"version": 4
}
13 changes: 13 additions & 0 deletions himanshi-khatri-skit-B230490/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "lldb",
"request": "launch",
"args": [],
"cwd": "/Users/himanshi/Documents/GitHub/CSR/himanshi-khatri-skit-B230490",
"program": "/Users/himanshi/Documents/GitHub/CSR/himanshi-khatri-skit-B230490/build/Debug/outDebug"
}
]
}
62 changes: 62 additions & 0 deletions himanshi-khatri-skit-B230490/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"C_Cpp_Runner.cCompilerPath": "clang",
"C_Cpp_Runner.cppCompilerPath": "clang++",
"C_Cpp_Runner.debuggerPath": "lldb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"ostream": "cpp"
}
}
3 changes: 3 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/abc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
him
89
67
Empty file.
Binary file not shown.
174 changes: 174 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/doubly_linkedlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include<iostream>
using namespace std;
class node{
public:
int data;
node*prev;
node*next;
// constructor
node(int data){
this->data=data;
this->prev=NULL;
this->next=NULL;
}
~node(){
int value=this->data;
if(next!=NULL){
delete next;
next=NULL;
}
cout<<"memory free for node with data"<<value;

}

};
void print(node*head){

node*temp=head;
while(temp!=NULL){
cout<<temp->data<<"\t";
temp=temp->next;
}
cout<<endl;

}
// traverse
int getLength(node*head){
int len=0;
node*temp=head;
while(temp!=NULL){
len++;
temp=temp->next;
}
return len;


}
void insertAtHead(node*&tail,node*&head,int item){
if(head==NULL){
node*temp=new node(item);
head=temp;
tail=temp;
}
else{
node*newnode= new node(item);
newnode->next=head;
head->prev=newnode;
head=newnode;

}

}
void insertAtTail(node* &tail,node*&head,int item){
if(tail==NULL){
node*temp=new node(item);
tail=temp;
head=temp;
}
else{
node* newnode= new node(item);
newnode->next=NULL;
tail->next=newnode;
tail=newnode;
}

}
void insertAtPosition(node*&head,node*&tail,int item,int pos){
int count;
node*temp=head;
// position is 1
if(pos==1){
insertAtHead(tail,head,item);
return;
}
// position is any
else{
node*newnode= new node(item);
while(count<pos){
temp=temp->next;
count++;
}
newnode->next=temp->next;
temp->next=newnode;
temp=newnode;
}
// position is last
if(temp->next==NULL){
insertAtTail(tail,head,item);
return;
}
// creating a node for item
node*nodeToInsert=new node(item);
nodeToInsert->next=temp->next;
temp->next->prev=nodeToInsert;
temp->next=nodeToInsert;
nodeToInsert->prev=temp;




}
// deletion of doubly ll
void deleteNode(int pos,node*&head){
// deleting starting node
if(pos==1){
node*temp=head;
temp->next->prev=NULL;
head=temp->next;
temp->next=NULL;
delete temp;
}
// deleting node in middle

else{
node*curr=head;
node*prev=NULL;
int count=0;
while(count<pos){
prev=curr;
curr=curr->next;
count++;

}
curr->prev=NULL;
prev->next=curr->next;
curr->next=NULL;
delete curr;

}
}
int main(){
node*head=NULL;
node*tail=NULL;


print(head);
// int n=getLength(head);
// cout<<endl<<n<<endl;
// insertAtHead(tail,head,15);

// insertAtHead(tail,head,60);

// insertAtHead(tail,head,62);
// insertAtTail(tail,head,45);
// insertAtPosition(head,tail,90,4 );
// insertAtPosition(head,tail,56,3);
// insertAtPosition(head,tail,87,1);
insertAtHead(tail,head,11);
print(head);
insertAtHead(tail,head,13);
print(head);
insertAtHead(tail,head,8);
print(head);
insertAtTail(tail,head,25);
print(head);
// insertAtPosition(tail,head,2,100);
// print(head);
// insertAtPosition(tail,head,1,101);
// print(head);
deleteNode(1,head);
cout<<"\n";
print(head);


}
3 changes: 3 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/even.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2
4
6
4 changes: 4 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.
I love working on DSA, JavaScript, and Python projects.
Currently, I'm exploring GitHub, improving my coding skills, and learning through CodeHelp and LeetCode.
I'm also a part of the Wisflux ILP program to expand my tech knowledge.
6 changes: 6 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/number.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
56
34
22
44
55
66
3 changes: 3 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/odd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1
3
5
Binary file added himanshi-khatri-skit-B230490/project-1/stream
Binary file not shown.
46 changes: 46 additions & 0 deletions himanshi-khatri-skit-B230490/project-1/stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{int n;
fstream of1("number.txt",ios::out);
fstream of2("odd.txt",ios::out);
fstream of3("even.txt",ios::out);


cout<<"enter number of data required: \n";
cin>>n;
int i=1;
cout<<"enter numbers \n";
int num;
while(i<=n){
cin>>num;
of1<<num<<endl;
i++;

}
of1.close();
of1.open("number.txt",ios::in);
int k=1;

while(k<=n){
if(k%2==0){
of3<<k<<endl;

}
else{
of2<<k<<endl;
}
k++;
}
of1.close();
of2.close();
of1.close();






}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insertAtHead(head,62);