0% found this document useful (0 votes)
9 views

Chep1 C Code Dsu

Uploaded by

jackmarquina080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chep1 C Code Dsu

Uploaded by

jackmarquina080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>

#include<stdlib.h>

typedef struct node {

int data;

struct node *next;

} node;

node *create();

void print(node *);

void search(node *, int);

node insert_b(node, int);

int main() { // Updated to "int main()"

int op, x;

node *head = NULL;

do {

printf("\n\n1)Create\n2)Insert(beginning)\n3)Search");

printf("\n4)Display\n5)Quit");

printf("\nEnter your choice: ");

scanf("%d", &op);

switch(op) {

case 1:

head = create();

break;

case 2:

printf("\nEnter the data to be inserted: ");


scanf("%d", &x);

head = insert_b(head, x);

break;

case 3:

printf("\nEnter the data to be searched: ");

scanf("%d", &x);

search(head, x);

break;

case 4:

print(head);

break;

} while(op != 5);

return 0; // Return 0 at the end of main

node *create() {

node *head = NULL, *p;

int i, n, x;

printf("\nEnter no. of data: ");

scanf("%d", &n);

printf("\nEnter data: ");

for(i = 0; i < n; i++) {

scanf("%d", &x);

if(head == NULL) {
p = head = (node*)malloc(sizeof(node));

head->next = NULL;

head->data = x;

} else {

p->next = (node*)malloc(sizeof(node));

p = p->next;

p->data = x;

p->next = NULL;

return(head);

node *insert_b(node *head, int x) {

node *p;

p = (node *)malloc(sizeof(node));

p->data = x;

p->next = head;

head = p;

return(head);

void print(node *head) {

printf("\n");

while(head != NULL) {

printf("%d ", head->data);

head = head->next;

}
}

void search(node *head, int x) {

int i = 1;

while(head != NULL && x != head->data) {

head = head->next;

i++;

if(head == NULL) {

printf("\nData not found");

} else {

printf("\nData found at location %d", i);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy