1.api接口
此问题没有深入研究,下面结果转自网上:
(一)Windows API
Windows API是一套用来控制Windows的各个部件的外观和行为的预先定义的Windows函数。用户的每个动作都会引发一个或几个函数的运行以告诉Windows发生了什么。这在某种程度上很像Windows的天然代码。而其他的语言只是提供一种能自动而且更容易的访问API的方法。当你点击窗体上的一个按钮时,Windows会发送一个消息给窗体,VB获取这个调用并经过分析后生成一个特定事件。
(二)linux API
在linux中,用户编程接口API遵循了UNIX中最流行的应用编程界面标准---POSIX标准。POSIX标准是由IEEE和ISO/IEC共同开发的标准系统。该标准基于当时现有的UNIX实践和经验,描述了操作系统的系统调用编程接口API,用于保证应用程序可以在源程序一级上在多种操作系统上移植运行。这些系统调用编程接口主要是通过C库(LIBC)来实现的。
2.编程语言如何控制硬件
汇编语言是通过寄存器操作硬件的,比如显示器操作方法:
mov ax, 0600h ; AH = 6, AL = 0h
mov bx, 0700h ; 黑底白字(BL = 07h)
mov cx, 0 ; 左上角: (0, 0)
mov dx, 0184fh ; 右下角: (80, 50)
int 10h ; int 10h
3. 微内核、宏内核与混合内核
只研究过微内核,微内核本身相当于一个消息传递系统(相当于邮局系统),负责把进程之间的消息传递给对方,对方处理完消息再传递回去,本身并不处理信息
4.主流架构指令集
此问题没有深入研究,下面结果转自网上:
芯片架构的选择大有讲究,不是随随便便就能决定的。芯片架构的出现与CPU息息相关,CPU也叫中央处理器,是一块超大规模的集成电路,主要包括运算器和高速缓冲存储器及实现它们之间联系的数据、控制及状态的总线。CPU的核心是各种类型的芯片,而芯片(指令集)架构则是造芯的第一步,指令集先进与否直接关系到CPU的性能发挥,目前市场上四大主流指令集为X86、MIPS、ARM、RISC-V。
http://oneindex.gentoo.site/PDF/%E3%80% … %E6%B4%8B).[PDF].&ckook.pdf
Gentoo Linux 11 LiveDVD快速安装法
安装步骤:
1. 分割磁区
2. 格式化分割区
3. 挂载分割区
4. 复制Live DVD Gentoo档案
5. 把环境切到硬碟
6. 修改root密码
7. 安装grub到 mbr
8. 设定、注解与停用服务
9. 复制kernel到 /boot区
10. 修改/etc/fstab
11. 编辑/boot/grub/grub.conf
12. 重开机,退出光碟
13. 完成基础Gentoo Live DVD安装
LiveDVD 光碟开机,不进X-Window开机,加快安装速度
boot: gentoo nox
分割磁区
这里是 boot 100M、SWAP 1G、ROOT 79G,其实 ROOT分割10G就可以了,如果不在安装什么的话!保险一点就是开大一点啰。
Livecd ~ # fdisk /dev/sda
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (15-10443, default 15): 1
Last cylinder, +cylinders or +size{K,M,G} (15-10443, default 10443):+100M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (15-10443, default 15): 15
Last cylinder, +cylinders or +size{K,M,G} (15-10443, default 10443): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (15-10443, default 15): 147
Last cylinder, +cylinders or +size{K,M,G} (15-10443, default 10443): 10443
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sda: 85.8GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x52a68f74
Device Boot Start End Blocks Id System
/dev/sda1 1 14 112423+ 83 Linux
/dev/sda2 15 146 1060290 82 Linux swap / Solaris
/dev/sda3 147 10443 82710652+ 83 Linux
Command (m for help): wq
格式化分割区
mkfs.ext3 /dev/sda1
mkswap /dev/sda2
mkfs.ext4 /dev/sda3
挂载分割区
swapon /dev/sda2
mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda1 /mnt/gentoo/boot
复制 Live DVD Gentoo文件
cp –apf /mnt/livecd/* /mnt/gentoo
===============================================================================
复制 kernel 到 /boot区
复制内核映像,从initramfs(把cache当作文件系统装载的思想)的LiveDVD到新系统。
mkdir -p /mnt/cdrom/
mount /dev/cdrom /mnt/cdrom/
cp /mnt/cdrom/boot/gentoo /boot/kernel
cp /mnt/cdrom/boot/gentoo.igz /boot/initramfs
------------------------------------------------------
方法2:
cp /usr/src/linux/System.map /boot/System.map-genkernel-x86-2.6.30-gentoo-r5
cp /usr/src/linux/arch/x86/boot/bzImage /boot/kernel-genkernel-x86-2.6.30-gentoo-r5
=============================================================================
cd
把环境切换到硬盘
chroot /mnt/gentoo /bin/bash
env-update && source /etc/profile
修改 root 密码
passwd
New password: ******
Retype new password: ******
passwd: password updated successfully
从默认boot中移除启动AutoConfig服务,否则您的root密码是每次启动时复位。
rc-update del autoconfig default 【经测试,这样会导至不能进入桌面,可以把passwd设为no并注释掉passwd段】
安装 grub 到 mbr
grub
root (hd0,0)
setup (hd0)
quit
注解 /etc/conf.d/local.start 里面全部东西,或用下面的指令清空
cat /dev/null > /etc/conf.d/local.start
rc-update del autoconfig
设定时区
rm /etc/localtime
ln –s /usr/share/zoneinfo/Asia/Taipei /etc/localtime
修改 /etc/fstab
/dev/sda1 /boot ext3 defaults 1 2
/dev/sda2 none swap sw 0 0
/dev/sda3 / ext4 defaults 0 1
===============================================
编辑 /boot/grub/grub.conf 内容如下
default 0
timeout 30
title Gentoo Linux 2.6.30-r6
root (hd0,0)
kernel /boot/kernel-genkernel-x86-2.6.30-gentoo-r5 root=/dev/rm0 real_root=/dev/sda3
initrd /boot/initramfs-genkernel-x86-2.6.30-gentoo-r5
退出环境,重开机,退出光碟
exit
reboot
===================================================
gentoo网络设置参考方法
/etc/conf.d/net文件的一个示例
# DHCP
config_eth0=( "dhcp" )
# 使用CIDR形式表示的静态IP
config_eth0=( "192.168.0.7/24" )
routes_eth0=( "default via 192.168.0.1" )
# 使用netmask形式表示的静态IP
config_eth0=( "192.168.0.7 netmask 255.255.255.0" )
routes_eth0=( "default via 192.168.0.1" )
启动和停止网络脚本
# /etc/init.d/net.eth0 start
# /etc/init.d/net.eth0 stop
* Messages for package sys-libs/gpm-1.20.7-r5:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package net-wireless/wpa_supplicant-2.10-r1:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package net-misc/networkmanager-1.40.6:
* Unable to find kernel sources at /usr/src/linux
* Messages for package sys-libs/glibc-2.36-r6:
* Generating all locales; edit /etc/locale.gen to save time/space
* Messages for package acct-group/colord-0:
* Adding group colord
* Messages for package acct-group/plugdev-0-r1:
* Adding group plugdev
* Messages for package acct-group/polkitd-0-r1:
* Adding group polkitd
* Messages for package acct-group/lpadmin-0-r1:
* Adding group lpadmin
* Messages for package dev-libs/ell-0.54:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package acct-group/messagebus-0-r1:
* Adding group messagebus
* Messages for package acct-user/polkitd-0-r1:
* Adding user polkitd
* Messages for package acct-user/colord-0:
* Adding user colord
* Messages for package acct-user/messagebus-0-r1:
* Adding user messagebus
* Messages for package app-alternatives/bzip2-1:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /bin/bzcat
* /bin/bunzip2
* /bin/bzip2
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/bzip2-1' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/gzip-0:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /bin/gzip
* /bin/gunzip
* /bin/zcat
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/gzip-0' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/awk-3:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /bin/awk
* /usr/bin/awk
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/awk-3' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/cpio-0:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /bin/cpio
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/cpio-0' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/tar-0:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /bin/tar
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/tar-0' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/lex-0-r1:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /usr/bin/lex
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/lex-0-r1' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package app-alternatives/yacc-1-r2:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /usr/bin/yacc
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/yacc-1-r2' merged despite file collisions.
* If necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package dev-lang/perl-5.36.0-r1:
* UPDATE THE PERL MODULES:
* After updating dev-lang/perl the installed Perl modules
* have to be re-installed. In most cases, this is done automatically
* by the package manager, but subsequent steps are still recommended
* to ensure system consistency.
*
* You should start with a depclean to remove any unused perl dependencies
* that may confuse portage in future. Regular depcleans are also encouraged
* as part of your regular update cycle, as that will keep perl upgrades working.
* Recommended: emerge --depclean -va
*
* You should then call perl-cleaner to clean up any old files and trigger any
* remaining rebuilds portage may have missed.
* Use: perl-cleaner --all
* Messages for package sys-apps/coreutils-9.1-r2:
* Make sure you run 'hash -r' in your active shells.
* You should also re-source your shell settings for LS_COLORS
* changes, such as: source /etc/profile
* Messages for package sys-libs/pam-1.5.2-r3:
* Some software with pre-loaded PAM libraries might experience
* warnings or failures related to missing symbols and/or versions
* after any update. While unfortunate this is a limit of the
* implementation of PAM and the software, and it requires you to
* restart the software manually after the update.
*
* You can get a list of such software running a command like
* lsof / | grep -E -i 'del.*libpam\.so'
*
* Alternatively, simply reboot your system.
* Messages for package perl-core/Encode-3.120.0:
* Unable to establish //usr/bin/encguess symlink
* Unable to establish //usr/share/man/man1/encguess.1.bz2 symlink
* Messages for package perl-core/CPAN-2.290.0-r1:
* Removing dead symlink //usr/bin/cpan-mirrors
* Removing dead symlink //usr/share/man/man1/cpan-mirrors.1.bz2
* Messages for package media-fonts/urw-fonts-2.4.9:
* If you upgraded from urw-fonts-2.1-r2 some fonts will look a bit
* different. Take a look at bug #208990 if interested.
* Messages for package media-fonts/liberation-fonts-2.1.5:
* The following fontconfig configuration files have been installed:
*
* 60-liberation.conf
*
* Use `eselect fontconfig` to enable/disable them.
* Messages for package app-misc/ca-certificates-20211016.3.86:
* Removing the following broken symlinks:
* /etc/ssl/certs/4304c5e5.0 -> Network_Solutions_Certificate_Authority.pem
* /etc/ssl/certs/03179a64.0 -> Staat_der_Nederlanden_EV_Root_CA.pem
* /etc/ssl/certs/349f2832.0 -> EC-ACC.pem
* Messages for package dev-libs/libinput-1.22.0:
* Install additional packages for optional runtime features:
* dev-python/python-libevdev for measure and replay tools
* Messages for package net-misc/dhcpcd-9.4.1:
*
* dhcpcd has zeroconf support active by default.
* This means it will always obtain an IP address even if no
* DHCP server can be contacted, which will break any existing
* failover support you may have configured in your net configuration.
* This behaviour can be controlled with the noipv4ll configuration
* file option or the -L command line switch.
* See the dhcpcd and dhcpcd.conf man pages for more details.
*
* Dhcpcd has duid enabled by default, and this may cause issues
* with some dhcp servers. For more information, see
* https://bugs.gentoo.org/show_bug.cgi?id=477356
*
* If you activate the lookup-hostname hook to look up your hostname
* using the dns, you need to install net-dns/bind-tools.
* Messages for package media-libs/fontconfig-2.14.1-r1:
* Please make fontconfig configuration changes using `eselect
* fontconfig`. Any changes made to /etc/fonts/fonts.conf will be
* overwritten. If you need to reset your configuration to upstream
* defaults, delete the directory /etc/fonts/conf.d/ and re-emerge
* fontconfig.
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/fontconfig-2.14.1-r1/README.gentoo*
* for future reference)
* Messages for package sys-devel/gcc-12.2.1_p20221210:
* No pre-generated info pages in tarball. Allowing regeneration with texinfo...
* Messages for package dev-libs/glib-2.74.3-r1:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package dev-qt/qtcore-5.15.7:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Generated gentoo-qconfig.h is empty
* Messages for package dev-qt/qtxml-5.15.7:
* Generated gentoo-qconfig.h is empty
* Messages for package dev-qt/qttest-5.15.7:
* Generated gentoo-qconfig.h is empty
* Messages for package sys-apps/util-linux-2.38.1:
* The mesg/wall/write tools have been disabled due to USE=-tty-helpers.
* Messages for package sys-auth/elogind-246.10-r2:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* elogind is currently not started from any runlevel.
* You may add it to the boot runlevel by:
* # rc-update add elogind boot
*
* Alternatively, you can leave elogind out of any
* runlevel. It will then be started automatically
* when the first service calls it via dbus, or
* the first user logs into the system.
* Messages for package sys-apps/dbus-1.15.2:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Some applications require a session bus in addition to the system
* bus. Please see `man dbus-launch` for more information.
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/dbus-1.15.2/README.gentoo*
* for future reference)
* Messages for package x11-misc/colord-1.4.6:
* The tmpfiles processor exited with a non-zero exit code
* Messages for package net-misc/modemmanager-1.18.12:
* If your USB modem shows up only as a storage device when you plug it
* in, then you should install sys-apps/usb_modeswitch, which will
* automatically switch it over to USB modem mode whenever you plug it
* in.
*
* To control your modem without needing to enter the root password, add
* your user account to the 'plugdev' group.
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/modemmanager-1.18.12/README.gentoo*
* for future reference)
* Messages for package app-alternatives/bc-0:
* This package will overwrite one or more files that may belong to other
* packages (see list below). You can use a command such as `portageq
* owners / <filename>` to identify the installed package that owns a
* file. If portageq reports that only one package owns a file then do
* NOT file a bug report. A bug report is only useful if it identifies at
* least two or more packages that are known to install the same file(s).
* If a collision occurs and you can not explain where the file came from
* then you should simply ignore the collision since there is not enough
* information to determine if a real problem exists. Please do NOT file
* a bug report at https://bugs.gentoo.org/ unless you report exactly
* which two packages install the same file(s). See
* https://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how
* to solve the problem. And once again, please do NOT file a bug report
* unless you have completely understood the above message.
*
* Detected file collision(s):
*
* /usr/bin/dc
* /usr/bin/bc
*
* Searching all installed packages for file collisions...
*
* Press Ctrl-C to Stop
*
* None of the installed packages claim the file(s).
*
* Package 'app-alternatives/bc-0' merged despite file collisions. If
* necessary, refer to your elog messages for the whole content of the
* above message.
* Messages for package sys-devel/llvm-15.0.6:
* You can find additional opt-viewer utility scripts in:
* /usr/lib/llvm/15/share/opt-viewer
* To use these scripts, you will need Python along with the following
* packages:
* dev-python/pygments (for opt-viewer)
* dev-python/pyyaml (for all of them)
* Messages for package media-libs/mesa-22.3.0:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* CONFIG_KCMP: is not set when it should be.
* Please check to make sure these options are set correctly.
* Failure to do so may cause unexpected problems.
* Messages for package x11-libs/pango-1.50.12:
* media-libs/freetype is installed without harfbuzz support. This may
* lead to minor font rendering problems, see bug 712374.
* Messages for package sys-libs/gpm-1.20.7-r5:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package net-print/cups-2.4.2-r6:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Messages for package net-wireless/bluez-5.66:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* To use dial up networking you must install net-dialup/ppp
* Messages for package x11-libs/gtk+-3.24.35:
* Please install app-text/evince for print preview functionality.
* Alternatively, check "gtk-print-preview-command" documentation and
* add it to your settings.ini file.
* Messages for package gnome-base/gnome-keyring-42.1-r1:
* Please select pinentry-gnome3 as default pinentry provider:
* # eselect pinentry set pinentry-gnome3
* Messages for package net-wireless/wpa_supplicant-2.10-r1:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* If this is a clean installation of wpa_supplicant, you have to create
* a configuration file named /etc/wpa_supplicant/wpa_supplicant.conf An
* example configuration file is available for reference in
* /usr/share/doc/wpa_supplicant-2.10-r1/
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/wpa_supplicant-2.10-r1/README.gentoo*
* for future reference)
* WARNING: You are building with TKIP support disabled, which is recommended since
* this protocol is deprecated and insecure. If you still need to connect to
* TKIP-enabled networks, you may turn this flag back on. With this flag off,
* TKIP-enabled networks, including mixed mode TKIP/AES-CCMP will not even show up
* as available. If your network is missing you may wish to USE=tkip
* Messages for package x11-libs/gtk+-2.24.33-r2:
* Please install app-text/evince for print preview functionality.
* Alternatively, check "gtk-print-preview-command" documentation and
* add it to your gtkrc.
* To make the gtk2 file chooser use 'current directory' mode by default,
* edit ~/.config/gtk-2.0/gtkfilechooser.ini to contain the following:
* [Filechooser Settings]
* StartupMode=cwd
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/gtk+-2.24.33-r2/README.gentoo*
* for future reference)
* Messages for package net-dialup/ppp-2.4.9-r8:
* Unable to find kernel sources at /usr/src/linux
* Unable to calculate Linux Kernel version for build, attempting to use running version
* Pon, poff and plog scripts have been supplied for experienced users.
* Users needing particular scripts (ssh,rsh,etc.) should check out the
* /usr/share/doc/ppp-2.4.9-r8/scripts directory.
* Messages for package net-misc/networkmanager-1.40.6:
* To modify system network connections without needing to enter the
* root password, add your user account to the 'plugdev' group.
*
* (Note: Above message is only printed the first time package is
* installed. Please look at /usr/share/doc/networkmanager-1.40.6/README.gentoo*
* for future reference)
* Regenerating GNU info directory index...
* Processed 102 info files.
* IMPORTANT: 1 news items need reading for repository 'gentoo'.
* Use eselect news read to view new items.
* After world updates, it is important to remove obsolete packages with
* emerge --depclean. Refer to `man emerge` for more information.
作者:semes 有疑问进群询问
第一步:安装dpkg
gentoo:sudo emerge dpkg
arch linux:sudo pacman -Sy dpkg //yay -S dpkg 看看那个行 你装apt也行
arch用户直接上archwiki的aur里面就有wechat,直接
git clone https://aur.archlinux.org/packages/wechat-uos
cd wechat-uos
makepkg -si //可能也不会看到这篇文章
centos/fedora/redhat: sudo dnf install dpkg -y //部分用户repo仓库里没有dpkg 要自己去找仓库
opensuse :sudo zypper install dpkg
kali/ubuntu/deepin //默认有dpkg,安装wechat包,可以直接跳过4,5步(应该不会有这类用户会看到这篇文章的,看到了在评论区举一个爪030)
第二步:去优麒麟官网下载wechat的deb包
网站在这:
微信
www.ubuntukylin.com/applications/106-cn.html
第三步:使用dpkg安装wechat
cd到wechat.deb包的位置
sudo dpkg -i wechat.deb //包名会随版本变化,此处请自行修改命令,或者你直接把包拖进终端
安装后有报错是正常现象,这个时候,wechat可以打开,但是wecaht扫码后无法登录
第四步:修正安装错误
sudo -s
ln -sf '/opt/weixin/weixin' '/usr/bin/weixin'
chmod 4755 '/opt/weixin/chrome-sandbox' || true
update-mime-database /usr/share/mime || true
update-desktop-database /usr/share/applications || true
mv /etc/lsb-release /etc/lsb-release-test //这个时候终端如果提醒你某个目录不存在, 那你就 mkdir -p 不存在的目录
mv /etc/lsb-release-ukui /etc/lsb-release
第五步:打开wechat,扫码验证自己的劳动成果
作者:semes 有疑问进群询问
参考了许多大佬的文章,还有gentoo官方的wiki,如果有哪位大佬看到文章里有你的内容,希望别生气哈
全过程root用户或者普通用户sudo,建立在gentoo已经安装完桌面的基础上,我就不讲gentoo整么安装了
gentoo linux安装nvidia(内核开始):
获取内核源码
emerge --ask sys-kernel/gentoo-sources
eselect kernel list
eselect kernel set 1
(可选)安装genkennel配置内核 ##有时候nvidia安装不上和内核配置有关,他需要根据你的内核配置文件来编译模块,所以我用genkernel,会自己陪内核的还是自己来配置内核
emerge --ask sys-kernel/genkernel
cd /usr/src/linux
genkernel all
禁用nouveau
mkdir /etc/modprobe.d/
touch /etc/modprobe.d/blacklist.conf
nano /etc/modprobe.d/blacklist.conf
#加入这些begin
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
#加入这些end
安装显卡驱动
nano /etc/portage/make.conf
#加入这些begin
VIDEO_CARDS="intel i965 iris nvidia" #Intel UHD630和Nvidia双显卡
#加入这些end
emerge -av x11-base/xorg-server x11-apps/xrandr x11-base/xorg-drivers media-libs/mesa x11-drivers/nvidia-drivers
配置nvidia
nano /etc/modules-load.d/nvidia.conf
#加入这些begin
nvidia
#加入这些end
systemctl start systemd-modules-load.service
或者
rc-update add modules boot
nano /etc/modprobe.d/nvidia-drm.conf
#加入这些begin
options nvidia-drm modeset=1
#加入这些end
nano /etc/X11/xorg.conf
##############加入这些begin##############################
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 440.100
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
Inactive "InactiveDevice1"
Option "AllowNVIDIAGPUScreens" "true"
Option "AllowPRIMEDisplayOffloadSink" "true"
EndSection
Section "Files"
EndSection
Section "InputClass"
Identifier "libinput pointer catchall"
Driver "libinput"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Option "AccelProfile" "flat" #禁用鼠标加速,玩游戏必备
Option "AccelSpeed" "0"
EndSection
Section "InputClass"
Identifier "libinput keyboard catchall"
Driver "libinput"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
EndSection
Section "InputClass"
Identifier "libinput touchpad catchall"
Driver "libinput"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
option "Tapping" "True"
option "TappingDrag" "True"
option "NaturalScrolling" "True"
EndSection
Section "Module"
Load "fb"
Load "shadow"
Load "exa"
Load "glamoregl"
Load "glx"
Load "dri3"
EndSection
Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
Option "DPMS"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:1:0:0"
Option "Accel" "true"
Option "RenderAccel" "true"
Option "NoFlip" "false"
Option "SWCursor" "false"
Option "HWCursor" "true"
Option "DamageEvents" "true"
Option "ModeDebug" "false"
Option "AllowSHMPixmaps" "false"
Option "SidebandSocketPath" "/tmp"
Option "UseSysmemPixmapAccel" "true"
Option "MultisampleCompatibility" "true"
Option "AllowEmptyInitialConfiguration" "true"
Option "ForceCompositionPipeline" "true"
Option "ForceFullCompositionPipeline" "true" #大幅度减少屏幕画面撕裂tearing,类似于垂直同步Vsync
Option "AllowIndirectGLXProtocol" "false"
Option "TripleBuffer" "true" #开启三重缓冲、并配合CompositionPipeline,能明显提升桌面和3D游戏的流畅度和响应速度,并且浏览器加载页面的速度也明显的感觉快了很多
Option "Stereo" "0"
Option "BaseMosaic" "false"
Option "MultiGPU" "false"
Option "SLI" "false"
Option "PrimaryGPU" "yes"
EndSection
Section "Device"
Identifier "InactiveDevice1"
Driver "modesetting"
VendorName "Unknown"
Option "AccelMethod" "glamor"
Option "DRI" "3"
Option "TearFree" "true"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection
Section "Screen"
Identifier "Screen1"
Device "InactiveDevice1"
EndSection
Section "ServerFlags"
Option "DontVTSwitch" "True"
Option "DontZap" "True"
EndSection
#############加入这些end###############
nano /usr/share/sddm/scripts/Xsetup
#加入这些begin
xrandr --setprovideroutputsource modesetting NVIDIA-0 #加入这一行
xrandr --auto #加入这一行
#加入这些end
chmod u+s /usr/bin/xinit
修改grub启动参数
nano /etc/default/grub
找到
#GRUB_CMDLINE_LINUX=""
改为
GRUB_CMDLINE_LINUX="nvidia-drm.modeset=1"
然后更新grub引导
grub-mkconfig -o /boot/grub/grub.cfg
#详细的intel&nvidia双显卡****prime****设置可以参照这位大佬的文章——
gentoo linux配置intel和nvidia双显卡电脑,使用prime方案
www.jianshu.com/p/515a1f39b438
换intel_GPU就改xorg.conf
把/etc/X11/xorg.conf的内容修改为:
##############################################################
Section "ServerLayout"
Identifier "layout"
Screen 0 "iGPU"
Option "AllowNVIDIAGPUScreens"
EndSection
Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:0:2:0"
EndSection
Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:1:0:0"
EndSection
###################################################################
安装timshift备份软件
Gentoo Portage Overlays - News
gpo.zugaina.org/
emerge layman
layman -a guru
layman -s guru
nano /etc/portage/package.keywords
#加入这些begin
app-backup/timeshift
#加入这些end
emerge app-backup/timeshift --autounmask-write
etc-update --automode -3
emerge app-backup/timeshift
安装gentoo储存库的steam
nano /etc/portage/make.conf
#加入这些begin
USE=" -gpm " ##解决一个循环依赖问题,我遇到的大问题,后面才想到备份系统
#加入这些end
安装 app-eselect/eselect-repository和dev-vcs/git:
emerge --ask --noreplace app-eselect/eselect-repository dev-vcs/git
添加 Steam 存储库:
eselect repository enable steam-overlay
或者layman -a steam-overlay
然后与任一特定的 emaint 同步:
emaint sync -r steam-overlay
或
emerge --sync
或
layman -s steam-overlay
nano /etc/portage/package.accept_keywords/steam
#加入这些begin
*/*::steam-overlay
#加入这些end
nano /etc/portage/package.keywords
#加入这些begin
games-util/game-device-udev-rules
#加入这些end
emerge games-util/steam-launcher games-util/steam-meta --autounmask-write
etc-update --automode -3
emerge games-util/steam-launcher games-util/steam-meta
安装过程要把依赖gpm的程序程序编译大概30几个包
我在安装steam的时候跌了一脚,我把gpm卸载了,大家遇到循环依赖的时候,不要向我一样哈,这导致了第11次重新安装系统
编译完后重启gentoo steam就可以正常用了
yum -y install binutils-* compat-libstdc++-* compat-libcap1-* elfutils-libelf-* elfutils-libelf-devel-* gcc* gcc-c++-* glibc* glibc-common-* glibc-devel-* glibc-headers-* ksh-* libaio-* libaio-devel-* libgcc-* libstdc++-* libstdc++-devel* make-* sysstat-* unixODBC-* unixODBC-devel-* numactl-devel-* pdksh-* kernel-headers* wget
umask 022
stty erase ^H
PATH=$PATH:$HOME/bin
TMP=/tmp
TMPDIR=$TMP
ORACLE_BASE=/home/oracle/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
ORACLE_SID=batsom
ORACLE_TERM=xterm
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export EDITOR=vi
export TMP TMPDIR ORACLE_TERM CLASSPATH NLS_DATE_FORMAT ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH NLS_LANG EDITOR
>>/home/oracle/.bash_profile
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
if [ $USER = "oracle" ]||[ $USER = "grid" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1054472192
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
/home/oracle/app/oraInventory/orainstRoot.sh
/home/oracle/app/oracle/product/11.2.0/db_1/root.sh
yum install haproxy -y
/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg
配置文件haproxy.cfg:
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend main
mode tcp
bind *:8081
log global
option tcplog
log-format %ft\ %b/%s
tcp-request inspect-delay 3s
acl is_https req.payload(0,3) -m bin 160301
#GET POS(T) PUT DEL(ETE) OPT(IONS) HEA(D) CON(NECT) TRA(CE)
acl is_http req.payload(0,3) -m bin 474554 504f53 505554 44454c 4f5054 484541 434f4e 545241
#SSH
acl is_ssh req.payload(0,3) -m bin 535348
tcp-request content accept if is_http
tcp-request content accept if is_https
tcp-request content accept if is_ssh
tcp-request content accept
use_backend https if is_https
use_backend http if is_http
use_backend ssr if is_ssh
use_backend ssr
backend ssr
mode tcp
timeout server 1h
server server-ssh 127.0.0.1:61000
backend http
mode tcp
server ngx01 127.0.0.1:80 maxconn 10 check inter 3s
backend https
mode tcp
server ngx02 127.0.0.1:433 maxconn 10 check inter 3s
tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
cd GNU-Linux-x86/
测试执行:
cd /home/sftp && rsync -artuz -R --delete ./ --port=873 root@192.168.110.3::bjjxj --password-file=/home/qinshun/shell/readfile/rsync.password
1.在主服务器上开启sersync守护进程,使sersync在后台运行,开启实时同步。
./sersync -d
2.在开启实时监控的之前对主服务器目录与远程目标机目录进行一次整体同步
./sersync -r
3.查看启动参数帮助
./sersync --help
4.指定配置文件
./sersync -o XXXX.xml
对于sersync使用可执行文件目录下的默认配置文件confxml.xml,如果需要使用另一个配置文件,可以使用-o参数指定其它配置文件。
5.指定默认的线程池的线程总数
./sersync -n num
例如 ./sersync -n 5 则指定线程总数为5,如果不指定,默认启动线程池数量是10,如果cpu使用过高,可以通过这个参数调低,如果机器配置较高,可以用-n跳高线程总数。
6.不进行同步,只运行插件
./sersync -m pluginName
例如./sersync -m command,则在监控到文件事件后,不对远程目标服务器进行同步,而是直接运行command插件。
7.多个参数可以配合使用
./sersync -n 8 -o abc.xml -r -d
表示,设置线程池工作线程为8个,指定abc.xml作为配置文件,在实时监控前作一次整体同步,以守护进程方式在后台运行。
8.通常情况下,对本地到远程整体同步一遍后,在后台运行实时同步。
./sersync -r -d
/*
Name: 线性表抽象数据类型(使用静态单链表实现)
Copyright:
Author: 巧若拙
Date:06-10-14 14:16
Description:
近一个月前我总结了线性表抽象数据类型(使用动态单链表实现),实际上更让我感兴趣的是静态链表。这种无需指针而有能够实现链表功能的结构,
对于那些不支持指针的高级语言来说,无疑是个巨大的福音。既可以像数组一样随机存取数据---它本身就是一个数组,又具有链表方便地实现插入和删除结点的功能;
由于它是模拟的"动态分配空间",实际上它的存储空间是由系统一次性分配好了的,这样在"动态分配空间"的时候,不需要内存管理程序,如果运行的Find函数相对较少,
它实现的速度比动态链表要快很多;此外,他很少出现因为内存空间不够的原因而导致程序不正常终止的情况,因为它的空间一早就分配好了,只要不超出链表的最大长度,
空间就足够。因此它真可以称的上是一个"宝贝"。
在链表的指针实现(即动态链表)中,有两个重要的特点:
1.数据存储在一组结构体中,每个结构包含有数据以及指向下一个结构体的指针。
2.一个新的结构体可以通过调用malloc()而从系统全局内存(global memory)得到,并可以通过调用free()而被释放.
静态链表必须能够模仿实现这两条特性。满足条件1的逻辑方法是要有一个全局的结构体数组,对于该数组中的任何单元(元素),其数组下标可以用来表示一个地址(结点)。
也就是说数组元素(结构体)包含有数据以及指向下一个结构体的游标---即下一个结点的数组下标.可以建立不同的链表,但实际上每一个链表都是结构体数组一部分元素的集合。
为了模拟条件2,我们需要建立一个"模拟空间分配站",它是一个规模较大的结构体数组。我们可以建立不同的链表,实际上我们创造的每一个链表都来自这个"模拟空间分配站",
每一个结点都是该结构体数组的元素,每一个链表都是结构体数组一部分元素的集合。
如果你曾经阅读过《线性表抽象数据类型(使用单链表实现) 》中的代码,你会发现动态链表和静态链表的基本操作的实现算法很相似,所有函数的接口都是一样的,主函数是一模一样的。
静态链表可以代替动态链表实现线性表的所有功能,而且速度更快。
*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
#define MAXSIZE 1000 //链表的最大长度
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef int ElemType;
typedef int Status; //函数类型,其值是函数结果状态代码,如OK等
typedef int Position;
typedef int LinkList;
struct Node{
ElemType data; //数据域
Position next;//指针域(游标)
} List[MAXSIZE]; //全局变量,静态链表的存储空间
void InitSpaceSL(void);//构造一个"模拟空间分配站",为全局变量
Position MallocSL(void); //"动态"分配空间给结点P
void FreeSL(Position P);//释放结点P的空间到"模拟空间分配站"
Status InitList(LinkList *L);//建立一个带头结点的空线性表L
Status ListEmpty(LinkList L);//判断线性表是否为空,若线性表为空,返回TRUE,否则返回FALSE
void DestroyList(LinkList *L);//销毁线性表L
Status ClearList(LinkList *L);//将线性表清空(只留下头结点)
int ListLength(LinkList L);//返回线性表L的元素个数
Status DisplayList(LinkList L);//输出线性表L的所有元素
Status GetElem(LinkList L, int i, ElemType *e);//将线性表L中第i个位置元素值赋给e
Status LocateElem(LinkList L, ElemType e);//在线性表L中查找是否存在与给定值e相等的元素
Status ListInsert(LinkList *L, int i, ElemType e);//在线性表L中的第i个位置之前插入新元素e
Status ListDelete(LinkList *L, int i, ElemType *e);//删除线性表L中的第i个位置,并将该元素值赋给e
int main(void)
{
LinkList a = NULL;
ElemType *p, e = 0;
int i;
InitSpaceSL(); //构造一个"模拟空间分配站",为全局变量
InitList(&a);//建立一个空的线性表
ListInsert(&a, 1, 1);
for (i=1; i<10; i++)
{
ListInsert(&a, i, i+100);
}
DisplayList(a);
printf("len = %d\n", ListLength(a));
for (i=1; i<ListLength(a); i+=2)
{
ListDelete(&a, i, &e);//删除线性表L中的第i个位置,并将该元素值赋给e
}
printf("len = %d\n", ListLength(a));
printf("e = %d\n", e);
DisplayList(a);
i = 5;
e = 1050;
if (LocateElem(a, e))//在线性表L中查找是否存在与给定值e相等的元素
{
printf("存在%d\n", e);
}
else
{
printf("不存在%d\n", e);
ListInsert(&a, i, e);
}
DisplayList(a);
ListDelete(&a, ListLength(a), &e);//删除线性表L中的最后一个元素
DisplayList(a);
ListDelete(&a, 1, &e);//删除线性表L中的第一个元素
DisplayList(a);
ClearList(&a);//将线性表清空(只留下头结点)
DisplayList(a);
return 0;
}
/*
函数名称:InitSpaceSL
函数功能:构造一个"模拟空间分配站",作为静态链表的存储空间.
初始化各结点的游标值,每个结点的游标值均表示其后继结点的数组下标
输入变量:无
输出变量;无
*/
void InitSpaceSL(void)
{
Position i;
for (i=0; i<MAXSIZE-1; i++) //每个结点的游标值均表示其后继结点的数组下标
{
List[i ].next = i + 1;
}
List[MAXSIZE-1].next = 0;//尾结点的后继结点下标为0,即NULL
}
Position MallocSL(void) //"动态"分配空间给结点P
{
Position P = 0;
if (List[0].next != 0) //还有空间
{
P = List[0].next;
List[0].next = List[P].next;
}
return P;
}
void FreeSL(Position P)//释放结点P的空间到"模拟空间分配站"
{
List[P].next = List[0].next;
List[0].next = P; //回收P结点的空间,实际上相当于入栈 ,List[0]即栈顶
}
Status InitList(LinkList *L)//建立一个带头结点的空线性表L
{
*L = MallocSL(); //为链表的头结点分配空间
if (!*L)
{
printf("Out of space!");
return ERROR;
}
List[*L].next = 0;
return OK;
}
Status ListEmpty(LinkList L)//判断线性表是否为空,若线性表为空,返回TRUE,否则返回FALSE
{
return (List[L].next == 0) ? TRUE : FALSE;
}
void DestroyList(LinkList *L)//销毁线性表L
{
Position s;
while (*L != 0)
{
s = List[*L].next;
FreeSL(*L);
*L = s;
}
}
Status ClearList(LinkList *L)//将线性表清空(只留下头结点)
{
Position q, s = List[*L].next;
while (s != 0)
{
q = List[s ].next;
FreeSL(s);
s = q;
}
List[*L].next = 0;
}
int ListLength(LinkList L)//返回线性表L的元素个数
{
Position s = List[L].next;
int count = 0;
while (s != 0)
{
count++;
s = List[s ].next;
}
return count;
}
Status DisplayList(LinkList L)//输出线性表L的所有元素
{
Position s = List[L].next;
int i = 0;
if (s == 0)
{
printf("none!\n");
return ERROR;
}
while (s != 0)
{
printf("data[%d] = %d, ", i++, List[s ].data);
s = List[s ].next;
}
printf("\n");
return OK;
}
Status GetElem(LinkList L, int i, ElemType *e)//将线性表L中第i个位置元素值赋给e
{
int j = 1;
Position s = List[L].next; //p指向第一个结点(非头结点)
while (s != 0 && j < i) //寻找第i个结点
{
j++;
s = List[s ].next;
}
if (s == 0 || j > i) //第i个元素不存在
{
return ERROR;
}
*e = List[s ].data;
return OK;
}
Status LocateElem(LinkList L, ElemType e)//在线性表L中查找是否存在与给定值e相等的元素
{
Position s = List[L].next;
while (s != 0)
{
if (List[s ].data == e)
return TRUE;
s = List[s ].next;
}
return FALSE;
}
Status ListInsert(LinkList *L, int i, ElemType e)//在线性表L中的第i个位置之前插入新元素e
{
int j = 1;
Position s, p = *L; //p指向头结点
while (p != 0 && j < i) //寻找第i-1个结点
{
j++;
p = List[p].next;
}
if (p == 0 || j > i) //第i-1个结点不存在
{
return ERROR;
}
s = MallocSL(); //为新结点分配空间
if (!s)
{
printf("Out of space!");
return ERROR;
}
List[s ].data = e;
List[s ].next = List[p].next;
List[p].next = s;
return OK;
}
Status ListDelete(LinkList *L, int i, ElemType *e)//删除线性表L中的第i个位置,并将该元素值赋给e
{
int j = 1;
Position q, p = *L; //p指向头结点
while (p != 0 && j < i) //寻找第i-1个结点
{
j++;
p = List[p].next;
}
if (List[p].next == 0 || j > i) //第i个结点不存在
{
return ERROR;
}
q = List[p].next; //q指向第i个结点
*e = List[q].data;
List[p].next = List[q].next;
FreeSL(q);
return OK;
}
算法进化历程之“水壶问题”
巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozhuo)
问题描述:假设给定了n个红色的水壶和n个蓝色的水壶,它们的形状和尺寸都不相同。所有红色水壶中所盛水的量都不一样,蓝色水壶也是一样。此外,对于每个红色的水壶,都有一个对应的蓝色水壶,两者所盛的水量是一样的。反之亦然。
你的任务是将所盛水量一样的红色水壶和蓝色水壶找出来。为了达到这一目的,可以执行如下操作:挑选出一对水壶,其中一个是红色的,另一个是蓝色的:将红色水壶中倒满水;再将水倒入到蓝色的水壶中。通过这个操作,可以判断出来这两只水壶的容量哪一个大,或者是一样大。假设这样的比较需要一个时间单位。你的目标是找出一个算法,它通过执行最少次数的比较,来确定分组和配对问题。记住不能直接比较两个红色的或两个蓝色的水壶。
思路分析:
为了验证配对是否正确,我在设计水壶的数据结构时安排了两个属性:水壶的储水量和水壶的编号。配对结束后,表示红蓝水壶的数组中下标相同的水壶储水量相同,但编号不一定相同。
数据结构如下:
typedef struct Kettle
{
int value;//水壶的储水量
int number; //水壶的编号
} Kettle;
为了确保每个红色水壶中所盛水的量都不一样,并且都有一个对应的蓝色水壶,我设计了一个函数为红壶和蓝壶随机初始化各不相同的储水量。代码如下:
void CreatKettle(Kettle BlueK[], Kettle RedK[], int n)
{
int i, j, pos, temp;
for (i=0; i<n; i++)
{
BlueK[i ].value = RedK[i ].value = BlueK[i ].number = RedK[i ].number = i + 1;
}
for (i=0; i<n; i++) //采用插入式洗牌,只改变储水量,不改变序号
{
pos = rand() % n;
temp = BlueK[0].value;
for (j=0; j<pos; j++)
BlueK[j].value = BlueK[j+1].value;
BlueK[pos].value = temp;
pos = rand() % n;
temp = RedK[0].value;
for (j=0; j<pos; j++)
RedK[j].value = RedK[j+1].value;
RedK[pos].value = temp;
}
}
版本一:简明易懂的版本
先介绍最简单的方法,拿出第1个红色水壶,然后从n个蓝色水壶中去配对,需要Θ(n)次比较,找到配对的蓝水壶后,将其交换到最左边,使其下标与对应红水壶的下标相同。
重复上述操作,直到所有的红色水壶都完成了配对。总的时间复杂度为Θ(n^2)。
代码如下:
void Match_1(Kettle BlueK[], Kettle RedK[], int n)//最简单的配对算法,时间复杂度为 Θ(n^2)
{
int i, j;
for (i=0; i<n; i++)
{
for (j=i; j<n; j++)
{
if (RedK[i ].value == BlueK[j].value)
{
Swap(&BlueK[j], &BlueK[i ]);
break;
}
}
}
}
void Swap(Kettle *a, Kettle *b)
{
Kettle temp = *a;
*a = *b;
*b = temp;
}
版本二:在配对某个红壶的同时将蓝壶分成两堆,以便缩小下一次配对的范围
在版本一中,每次为红壶配对,都要遍历未配对的所有蓝壶,效率较低。我们可以在配对某个红壶的同时将蓝壶分成两堆,以便缩小下一次配对的范围,提高效率。代码如下:
void Match_2(Kettle BlueK[], Kettle RedK[], int n)
{
int i, pos;
pos = Partition(BlueK, RedK[0].value, 0, n-1);//先配对第一个红壶
Swap(&BlueK[0], &BlueK[pos]);//将已配对水壶交换到最左边
for (i=1; i<n; i++)//依次配对剩下的红壶
{
if (RedK[i ].value < BlueK[i-1].value)
pos = Partition(BlueK, RedK[i ].value, i, pos);//在[i,pos]范围内寻找配对
else
pos = Partition(BlueK, RedK[i ].value, pos+1, n-1);//在[pos+1, n-1]范围内寻找配对
Swap(&BlueK[i ], &BlueK[pos]);//将已配对水壶交换到最左边
}
}
Match_2()用到一个分割函数Partition(),这是一个类似快速排序的分割函数,可以以值为x的元素为枢纽元,将数组K[]分成两部分,并返回枢纽元的位置。代码如下:
int Partition(Kettle K[], int x, int left, int right)
{
while (left < right)
{
while (K[left].value < x)
left++;
while (K[right].value > x)
right--;
Swap(&K[left], &K[right]);
}
return left;
}
版本三:类快速排序算法
由于每个红色水壶中所盛水的量都不一样,并且都有一个对应的蓝色水壶,因此我们只需分别将其进行排序即可。但是不能直接比较同种颜色的水壶,只有颜色不一样的水壶才能进行比较,因此需要交叉比较,互为枢纽元素。
整个排序过程中利用快速排序的思想,调用了版本二中的分割函数Partition(),采用交叉分割的方法,具体描述如下:
1. 从红色水壶序列中随机选择一个作为枢轴元素
2. 利用红色水壶枢轴元素RedK[posRedK]对蓝色水壶序列进行分割,并返回对应蓝色水壶的编号posBlueK。
3. 利用BlueK[posBlueK]对红色水壶序列进行进行分割,并返回对应红色水壶的编号posRedK,很显然此时posRedK ==posBlueK。
4.递归调用函数QuickMatch(),对分割好的序列进行配对。
算法的时间复杂度为O(nlgn),最坏的情况下时间复杂度为O(n^2)。
代码如下:
void Match_3(Kettle BlueK[], Kettle RedK[], int n)//快速配对算法的驱动函数
{
QuickMatch(BlueK, RedK, 0, n-1);
}
void QuickMatch(Kettle BlueK[], Kettle RedK[], int left, int right)//类似快速排序的快速配对算法
{
int posBlueK, posRedK;
if (left < right)
{
posRedK = rand() % (right-left+1) + left; //从红色水壶中随机选择一个作为枢轴元素
posBlueK = Partition(BlueK, RedK[posRedK].value, left, right);//将蓝壶分成两堆,并返回配对蓝壶的编号
posRedK = Partition(RedK, BlueK[posBlueK].value, left, right); //将红壶分成两堆,并返回配对红壶的编号
//递归调用函数QuickMatch(),对分割好的序列进行配对
QuickMatch(BlueK, RedK, left, posRedK-1);
QuickMatch(BlueK, RedK, posRedK+1, right);
}
}
测试主函数:
int main(void)
{
Kettle BlueK[MAXSIZE], RedK[MAXSIZE];
int i, n = 6;
CreatKettle(BlueK, RedK, n);
Print(BlueK, RedK, n);
Match_1(BlueK, RedK, n);
// Match_2(BlueK, RedK, n);
// Match_3(BlueK, RedK, n);
Print(BlueK, RedK, n);
return 0;
}
输出数据函数:
void Print(Kettle BlueK[], Kettle RedK[], int n)
{
int i;
for (i=0; i<n; i++)
{
printf ("BlueK[%d]: %d, %d RedK[%d]: %d, %d\n", i, BlueK[i ].number, BlueK[i ].value, i, RedK[i ].number, RedK[i ].value);
}
printf("\n");
}
巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozhuo)
遍历二叉树的递归函数是体现了算法之美的高妙算法,思路清晰,代码简洁,读之赏心悦目。代码如下:
程序代码:
void PreOrderTraverse_R(BiTree BT)//采用递归方式先序遍历二叉树BT
{
if(BT != NULL)
{
printf("%c", BT->data);//输出该结点(根结点)
PreOrderTraverse_R(BT->lchild); //遍历左子树
PreOrderTraverse_R(BT->rchild);//遍历右子树
}
}
void InOrderTraverse_R(BiTree BT)//采用递归方式中序遍历二叉树BT
{
if(BT != NULL)
{
InOrderTraverse_R(BT->lchild); //遍历左子树
printf("%c", BT->data);//输出该结点(根结点)
InOrderTraverse_R(BT->rchild);//遍历右子树
}
}
void PostOrderTraverse_R(BiTree BT)//采用递归方式后序遍历二叉树BT
{
if(BT != NULL)
{
PostOrderTraverse_R(BT->lchild); //遍历左子树
PostOrderTraverse_R(BT->rchild);//遍历右子树
printf("%c", BT->data);//输出该结点(根结点)
}
}
相较之下,大部分流传的非递归遍历二叉树算法语言晦涩,面目可憎,虽然利用了栈数据结构来模拟递归遍历过程,但思路和表达形式上未能与递归算法对应起来,造成初学者理解上的困惑。如果能够将非递归算法和递归算法相互对应,则可大大方便初学者理解二者间的等效性。
我们知道,编译器在调用函数时会分配一个栈空间,以存储必要信息,如果该函数调用了别的函数,其栈空间会一直保留,直到该函数最后一条语句执行完毕,才会释放其栈空间。在模拟非递归算法的时候,我们需要手工分配和释放栈空间。
三种不同的遍历方式区别在于栈空间的释放时机和输出结点信息时机的不同:先序和中序遍历是在访问栈顶元素的右孩子(右子树)之前退栈,而后序遍历在访问右子树之后退栈;先序遍历是在某结点入栈时输出其信息,而中序和后序遍历是在该结点退栈时输出其信息。
无论是递归算法还是非递归算法,都遵循上述规则,二者可以一一对应。