Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test sample #735

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": ".",
"program": "build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"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
}
93 changes: 93 additions & 0 deletions Data Structure Using C/array/array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include<stdio.h>
#define size 50

int main(){
int n=5,arr[size]={1,2,3,4,5};
int choice,ele,pos,i;
int low=1,high=n,mid,flag=0;
while(1){
printf("1.Traverse\n2.Insert\n3.Delete\n4.Sequentciatly Search\n5.Binary Search\n6.Exit\n");
printf("Enter Your Choice: ");
scanf("%d",&choice);
switch(choice){
case 1:
for(i=0;i<n;i++){
printf("%d ",arr[i]);
}
break;
case 2:
printf("Enter element which you want to insert: ");
scanf("%d",&ele);
printf("Enter position where you want to insert the element: ");
scanf("%d",&pos);
for(i=n-1;i>=pos;i--){
arr[i+1]=arr[i];
printf("POS: %d I: %d ARR[i]: %d ARR[i+1]: %d\n",pos,i,arr[i],arr[i+1]);
}
arr[pos]=ele;
n++;
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
break;
case 3:
printf("Enter position where you want to delete the element: ");
scanf("%d",&pos);
int temp=arr[pos];
for(i=pos;i<n;i++){
printf("POS: %d I: %d ARR[i]: %d ARR[i+1]: %d\n",pos,i,arr[i],arr[i+1]);
arr[i]=arr[i+1];
}
n--;
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
break;
case 4:
printf("Enter Element: ");
scanf("%d",&ele);
i=0;
while(i<n){
if(arr[i]==ele){
printf("Search Succesfull %d found on %d index",ele,i);
flag=1;
break;
}
i++;
}
if(flag==0){
printf("%d is not found.",ele);
}
break;
case 5:
low=1;
high=n;
mid=0;
printf("Enter Element: ");
scanf("%d",&ele);
while(low<=n){
mid=(low+high)/2;
if(ele<arr[mid]){
high=mid-1;
}else if(ele>arr[mid]){
low=mid+1;
}else{
printf("Search Succesfully! %d founded",ele);
flag=1;
break;
}
}
if(flag==0){
printf("%d is not found.",ele);
}
break;
case 6:
return 0;
default:
printf("Please! Enter valid choice.");

}
printf("\n\n");
}
return 0;
}
136 changes: 136 additions & 0 deletions Data Structure Using C/linked-list/linked-list-doubly.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include <stdio.h>
#include <stdlib.h>

// Define the structure of a node
struct Node {
int data;
struct Node* next;
};

struct Node* head = NULL; // Head pointer to the singly linked list

// Function to traverse and display the list
void traverse() {
if (head == NULL) {
printf("List is empty.\n");
} else {
struct Node* temp = head;
printf("List: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
}

// Function to insert a node at the end
void insertNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;

if (head == NULL) {
head = newNode; // If the list is empty
} else {
struct Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode; // Insert at the end
}
printf("%d inserted into the list.\n", data);
}

// Function to delete a node by value
void deleteNode(int value) {
if (head == NULL) {
printf("List is empty. Nothing to delete.\n");
return;
}
struct Node *temp = head, *prev = NULL;

// Check if the head node needs to be deleted
if (temp != NULL && temp->data == value) {
head = temp->next;
free(temp);
printf("%d deleted from the list.\n", value);
return;
}

// Traverse to find the node to delete
while (temp != NULL && temp->data != value) {
prev = temp;
temp = temp->next;
}

if (temp == NULL) { // Value not found
printf("Value %d not found in the list.\n", value);
return;
}

prev->next = temp->next; // Unlink the node
free(temp);
printf("%d deleted from the list.\n", value);
}

// Function to search for a node
void searchNode(int value) {
struct Node* temp = head;
int position = 1;

while (temp != NULL) {
if (temp->data == value) {
printf("%d found at position %d.\n", value, position);
return;
}
temp = temp->next;
position++;
}
printf("%d not found in the list.\n", value);
}

// Main function
int main() {
int choice, value;

printf("SINGLY LINKED LIST IMPLEMENTATION\n\n");
while (1) {
printf("Menu:\n");
printf("1. Traverse\n");
printf("2. Insert Node\n");
printf("3. Delete Node\n");
printf("4. Search Node\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
traverse();
break;
case 2:
printf("Enter value to insert: ");
scanf("%d", &value);
insertNode(value);
break;
case 3:
printf("Enter value to delete: ");
scanf("%d", &value);
deleteNode(value);
break;
case 4:
printf("Enter value to search: ");
scanf("%d", &value);
searchNode(value);
break;
case 5:
printf("Exiting...\n");
return 0;
default:
printf("Invalid choice. Try again.\n");
}
printf("\n");
}
return 0;
}
Loading