#include<stdio.h> #include<stdlib.h> struct node{ int data; node next; }; struct…
- User
#include<stdio.h> #include<stdlib.h> struct node{ int data; node *next; }; struct nganxep{ node *top; }; void khoitao(nganxep *s){ s->top = NULL; } // cap phat bo nho ; node *tao_node( int x){ node p = (node) malloc (sizeof (node)); p->data =x; p->next = NULL; return p; } void them ( nganxep *s , int x){ node *p = tao_node(x); if ( s->top == NULL){ s->top = p ; }else { p->next = s->top ; s->top = p; } } void lay( nganxep *s){ if ( s->top == NULL){ printf("ngan xep rong:"); }else{ node *temp = s->top ; s->top = temp->next; } } void nhap ( nganxep *s , int x){ int n; printf("nhap vao so luong phan tu:"); scanf("%d",&n); for ( int i=0; i< n ; i++){ scanf("%d", &x); them(s,x); } } void xuat ( nganxep *s ){ node *temp = s->top ; while ( temp != 0){ if(temp->data %2 != 0 && temp->data %3 ==0){ printf("%d ", temp -> data); } temp=temp->next; } printf("\n"); } int main (){ int x; struct nganxep s; khoitao(&s); nhap(&s,x); xuat(&s); }
- Assistant
The provided C program implements a simple stack (ngăn xếp) using a linked list data structure. The structure consists of two main parts: and . Here’s a walk-through of the program:
- User
Cho một ngăn xếp chứa tối đa m số nguyên. Viết chương trình thực hiện các yêu cầu sau: Câu 1 (6 điểm)
- Biểu diễn ngăn xếp bởi con trỏ
- Viết hàm nhập dữ liệu cho ngăn xếp
- Viết hàm hiển thị dữ liệu trong ngăn xếp ra màn hình
- Assistant
- User
#include<stdio.h> #define N 50 struct danhsach{ int data[N]; int size; }; void khoitao( danhsach &l){ l.size=0; } void nhap( danhsach &l ){ printf("nhap vao so luong danh sach:"); scanf("%d",&l.size); for ( int i=0 ; i<l.size ; i++){ scanf("%d",&l.data[i]); } } void xuat( danhsach &l){ for( int i=0; i<l.size ; i++){ printf("%d ",l.data[i]); } printf("\n"); } void xoa_dau(danhsach &l){ if(l.size==0){ printf("danh sach rong:"); } for ( int i=0 ; i<l.size-1 ; i++){ l.data[i] =l.data[i+1]; } l.size--; printf("da xoa danh sach:"); } void tach_danh_sach( danhsach &l , danhsach &l1 , danhsach &l2){ khoitao(l1); khoitao(l2); for ( int i=0; i< l.size ; i++){ if( l.data[i] %2 ==0){ l1.data[l1.size++] = l.data[i]; } else{ l2.data[l2.size++] = l.data[i]; } } } int main(){ struct danhsach l,l1,l2; khoitao(l); nhap(l); xuat(l); xoa_dau(l); xuat(l); tach_danh_sach(l,l1,l2); xuat(l1); xuat(l2); }
- Assistant
- User
Cho một danh sách chứa tối đa N sinh viên. Mỗi sinh viên cần quản lý các thông tin Họ tên, Giới tính, Điểm trung bình. Yêu cầu: Câu 1 (6 điểm)
- Biểu diễn danh sách bởi mảng
- Viết hàm nhập dữ liệu cho danh sách
- Viết hàm hiển thị dữ liệu trong danh sách ra màn hình
- Assistant