Skip to content
Merged
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
57 changes: 22 additions & 35 deletions Conversions/decimal _to_binary.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
/*********decimal number to binary number conversion*****************/
#include <stdio.h>
void decimal2Binary(long num);

int main(){

long num;

printf("Enter a decimal integer \n");
scanf("%ld", &num);
decimal2Binary(num);

return 0;
}

/***function for convert decimal numbers to binary numbers****************/
void decimal2Binary(long num){

long decimal_num, remainder, base, binary, no_of_1s;

base = 1;
binary = 0;
no_of_1s = 0;
#include<stdio.h>
int main()
{
int n,re,a[10000],j;
printf("\nenter the no ");
scanf("%d",&n);
int i=0;
while(n>0)
{

while (num > 0)
re=n%2;
a[i]=re;
n=n/2;
i++;
}
int k;
k=i-1;
printf("\n the number in binary is: ");
for(j=k;j>=0;j--)
{
remainder = num % 2;

if (remainder == 1)
{
no_of_1s++;
}
binary = binary + remainder * base;
num = num / 2;
base = base * 10;}

printf("Its binary equivalent is = %ld\n", binary);
printf("%d",a[j]);
}
return(0);
}

121 changes: 76 additions & 45 deletions Data Structures/linked_list/singly_link_list_deletion.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,96 @@
function can be modified according to the data type, easily.
deleteNode deletes a node when passed with a key of the node.
*/
#include <stdio.h>
#include <stdlib.h>

struct Node
{
int data;
struct Node *next;
#include<stdio.h>
struct node
{int info;
struct node *link;
};

void push(struct Node** head_ref, int new_data)
struct node *start=NULL;
///////////////////////////////////////////////////////////
struct node * createnode()//function to create node
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
struct node *t;
t=(struct node*)malloc(sizeof(struct node));
return(t);
}

void deleteNode(struct Node **head_ref, int key)
////////////////////////////////////////////////////////
void insert()//function to insert at first location
{
struct Node* temp = *head_ref, *prev;

if (temp != NULL && temp->data == key)
struct node *p;
p=createnode();
printf("\nenter the number to insert");
scanf("%d",&p->info);
p->link=NULL;
if(start==NULL)
{
start=p;
}
else
{
p->link=start;
start=p;
}
}
///////////////////////////////////////////////////////////
void deleteion()//function to delete from first position
{
struct node *t;
if(start==NULL)
{
*head_ref = temp->next;
free(temp);
return;
printf("\nlist is empty");
}


while (temp != NULL && temp->data != key)
else
{
prev = temp;
temp = temp->next;
struct node *p;
p=start;
start=start->link;
free(p);
}

if (temp == NULL) return;

prev->next = temp->next;

free(temp);
}

void printList(struct Node *node)
///////////////////////////////////////////////////////
void viewlist()//function to display values
{
while (node != NULL)
struct node *p;
if(start==NULL)
{
printf(" %d ", node->data);
node = node->next;
printf("\nlist is empty");
}
else
{ p=start;
while(p!=NULL)
{
printf("%d ",p->info);
p=p->link;
}
}
}
//////////////////////////////////////////////////////////////////////

int main()
{
/* new node can be created here as :-
struct Node* head = NULL;
push(&head, data);

and a node can be delete by using
deleteNode(&head, key);
*/
return 0;
int n;
while(1)
{
printf("\n1.add value at first location");
printf("\n2.delete value from first location");
printf("\n3.view value");
printf("\nenter your choice");
scanf("%d",&n);
switch(n)
{
case 1:
insert();
break;
case 2:
deleteion();
break;
case 3:
viewlist();
break;
default:
printf("\ninvalid choice");
}
}
return(0);
}